469,928 Members | 1,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

System.InvalidCastException: Unable to cast object of type 'System.Xml.XmlDocument' to type 'System.String'


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? :(
Apr 13 '06 #1
2 12898

When I change this line:

results = this.Invoke("validate", new object[] { xmlDocument });

into this:

results = this.Invoke("validate", new object[] {
xmlDocument.OuterXml.ToString() });

it (almost) works. The problem is that it wraps my XML document into <url
http://www.example.org/Avtentikacija"> my xml here...</url> inside
<soap:body>, like this:

<soap:Body>
<url xmlns="http://sigen.si/Avtentikacija">
MyXML here...
</url>
</soap:Body>

Why? I don't want this! Webservice that I call can't parse it. It doesn't
expects <url></url> :(
Apr 13 '06 #2
We need full service description, generated client proxy and request.xml to
figure out what is going wrong here. Could you please provde this
information?

Thanks,

Zafar

"John Smith" <jo********@microsoft.com> wrote in message
news:Kj*******************@news.siol.net...

When I change this line:

results = this.Invoke("validate", new object[] { xmlDocument });

into this:

results = this.Invoke("validate", new object[] {
xmlDocument.OuterXml.ToString() });

it (almost) works. The problem is that it wraps my XML document into <url
http://www.example.org/Avtentikacija"> my xml here...</url> inside
<soap:body>, like this:

<soap:Body>
<url xmlns="http://sigen.si/Avtentikacija">
MyXML here...
</url>
</soap:Body>

Why? I don't want this! Webservice that I call can't parse it. It doesn't
expects <url></url> :(

Apr 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Fidias Gil de Montes | last post: by
4 posts views Thread by John Smith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.