Connecting Tech Pros Worldwide Forums | Help | Site Map

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

John Smith
Guest
 
Posts: n/a
#1: Apr 13 '06

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? :(



John Smith
Guest
 
Posts: n/a
#2: Apr 13 '06

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



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> :(


Zafar Abbas
Guest
 
Posts: n/a
#3: Apr 14 '06

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


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" <john.smith@microsoft.com> wrote in message
news:Kjr%f.1740$oj5.667192@news.siol.net...[color=blue]
>
> 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> :(
>
>[/color]


Closed Thread