I'm writing webervice client using .Net 2.0. I have this class:
[System.Web.Services.WebServiceBindingAttribute(Nam e = "ValidateBinding",
Namespace = "http://example.org/Avtentikacija")]
public class MyWebService : SoapHttpClientProtocol
{
[System.Web.Services.Protocols.SoapDocumentMethodAt tribute("", Use =
System.Web.Services.Description.SoapBindingUse.Lit eral, ParameterStyle =
System.Web.Services.Protocols.SoapParameterStyle.B are)]
public XmlDocument validate(string url,
[System.Xml.Serialization.XmlElementAttribute(Names pace =
"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.XmlS erializationWriterMyWebService.Write1_validate(Obj ect[]
p)
at
Microsoft.Xml.Serialization.GeneratedAssembly.Arra yOfObjectSerializer.Serialize(Object
objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Serialize(SoapClientMessage
message)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.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? :(