For Programmers: Free Programming Magazines  


Home > Archive > Microsoft Webservices > April 2006 > System.InvalidCastException: Unable to cast object of type 'System.Xml.XmlDocument' t









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author System.InvalidCastException: Unable to cast object of type 'System.Xml.XmlDocument' t
John Smith

2006-04-13, 4:12 am


I'm writing webervice client using .Net 2.0. I have this class:

[System.Web.Services.WebServiceBindingAttribute(Name = "ValidateBinding",
Namespace = "http://example.org/Avtentikacija")]
public class MyWebService : SoapHttpClientProtocol
{
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use =
System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle =
System.Web.Services.Protocols.SoapParameterStyle.Bare)]
public XmlDocument validate(string url,
[System.Xml.Serialization.XmlElementAttribute(Namespace =
"http://www.example.org/PodpisaniDokument")] XmlDocument xmlDocument)
{
this.Url = url;
object[] results = null;
try
{
// ERROR occur at this line :(
results = this.Invoke("validate", new object[] { xmlDocument });
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
return ((XmlDocument)(results[0]));
}
}

and I call it like this:

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.Load("C:\\request.xml");

MyWebService web = new MyWebService();
xmlDocument =
web.validate("http://localhost:8080/MyWeb/services/Avtentikacija",
xmlDocument);
if (xmlDocument != null)
xmlDocument.Save("C:\\response.xml");

And I got this error message:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidCastException: Unable to cast object of type
'System.Xml.XmlDocument' to type 'System.String'.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMyWebService.Write1_validate(Object[]
p)
at
Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Serialize(Object
objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at
System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientMessage
message)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
at MyWeb.MyWebService.validate(String url, XmlDocument xmlDocument) in
C:\Documents and Settings\I\My Documents\Visual Studio
2005\Projects\MyWeb\MyWeb\Form1.cs:line 152

Why? :(



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com