Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.sdk
[Q] SoapFormatter.Deserialize gives exception
Pranav Mundi
10/14/2002 7:11:00 AM
Hi,
I am using SoapFormatter.Deserialize method for
deserializing a Soap message to get the SoapMessage object.
The code gives me the following exception:
----------------------------------------------
An unhandled exception of
type 'System.Runtime.Serialization.SerializationException'
occurred in
system.runtime.serialization.formatters.soap.dll
Additional information: Parse Error, no assembly
associated with Xml key tns ProfileInfoHeader
----------------------------------------------
Following is the code I am trying to execute:
public static void StreamToSOAPMessage()
{
Console.WriteLine
("SOAPStreamToSOAPMessage\n");
SoapFormatter formatter = new
SoapFormatter();
MemoryStream stream = new
MemoryStream();
StreamWriter tw = new StreamWriter
(stream);
tw.Write("<?xml version=\"1.0\"
encoding=\"utf-8\"?><soap:Envelope
xmlns:xsi=\"
http://www.w3.org/2001/XMLSchem...
\"
xmlns:xsd=\"
http://www.w3.org/2001...
\"
xmlns:soapenc=\"
http://schemas.xmlsoap.org/soap...
\" xmlns:tns=\"
http://te...
\"
xmlns:types=\"
http://te...
encodedTypes\"
xmlns:soap=\"
http://schemas.xmlsoap.org/soap...
\">
<soap:Header> <tns:ProfileInfoHeader> <ProfileID
xsi:type=\"xsd:string\">string</ProfileID>
<ProfileName
xsi:type=\"xsd:string\">string</ProfileName>
<CallingModuleName
xsi:type=\"xsd:string\">string</CallingModuleName>
</tns:ProfileInfoHeader> </soap:Header> <soap:Body
soap:encodingStyle=\"
http://schemas.xmlsoap.org/s...
ng/\"> <tns:AddNumbers
xsi:type=\"tns:AddNumbers\"> <Num1
xsi:type=\"xsd:int\">int</Num1> <Num2 href=\"#id1
\" /> <String1
xsi:type=\"xsd:string\">string</String1>
</tns:AddNumbers> <soapenc:Array id=\"id1\"
soapenc:arrayType=\"xsd:int[2]
\"><Item>int</Item><Item>int</Item></soapenc:Array></soap:B
ody></soap:Envelope>");
tw.Flush();
stream.Position = 0;
SoapMessage soapMessage = new
SoapMessage();
formatter.TopObject = soapMessage;
HeaderHandler headerHandler = new
HeaderHandler(ParseHeaders);
soapMessage = (SoapMessage)
formatter.Deserialize(stream);
String xmlNameSpace =
soapMessage.XmlNameSpace;
Console.WriteLine("XmlNameSpace "+
xmlNameSpace);
String methodName =
soapMessage.MethodName;
Console.WriteLine
("methodName "+methodName);
Object[] parameters =
soapMessage.ParamValues;
int[] nIDs = (int[]) parameters[1];
for (int i=0; i<parameters.Length;
i++)
Console.WriteLine
("param "+i+" "+parameters[i].GetType());
Console.WriteLine("\n");
}
--------------------------------------------------------
The Soap message was for the web service whose code is
given below:
---------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Runtime.Remoting.Metadata;
using System.Xml.Serialization;
namespace BRHttpMods
{
/// <summary>
/// Summary description for Service1.
/// </summary>
///
[SoapDocumentService(Use=SoapBindingUse.Encoded,
ParameterStyle=SoapParameterStyle.Wrapped)]
public class Service1 :
System.Web.Services.WebService
{
public ProfileInfoHeader m_PFI;
public Service1()
{
//CODEGEN: This call is required
by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod]
[SoapHeader("m_PFI")]
public string AddNumbers(int Num1,int []
Num2, string String1)
{
int Sum = 0;
for (int i = 0 ; i < Num2.Length ;
i ++)
{
Sum = Num1 + Num2[i];
}
return (Sum.ToString());
}
}
public class ProfileInfoHeader: SoapHeader
{
public string ProfileID;
public string ProfileName;
public string CallingModuleName;
}
}
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
[Q] SoapFormatter.Deserialize gives exception
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password