By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,666 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,666 IT Pros & Developers. It's quick & easy.

System.InvalidCastException: Cannot assign object of type System.Xml.XmlNode[] to an object of type System.String.

P: n/a
Hi!

I'm working with a C# client that calls a php web service. I've
created a wrapper to call the service using .NET wsdl tool (adding a
web reference).

The call to the server works fine, it is serialized correctly, and the
server returns a response (I've captured the response and it's
correct!) but when the .NET deserialize this response, it throws the
exception "System.InvalidOperationException: There is an error in XML
document (1, 541). ---> System.InvalidCastException: Cannot assign
object of type System.Xml.XmlNode[] to an object of type
System.String." (The full exception text is detailed at the end of the
message).

The particular thing of the web service operation is that uses input
and output parameters, perhaps that's the problem?

Can anybody helps me?

Thanks a lot in advance,

Marc.

************ WSDL starts here ***************
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="urn:emisiowsdl"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="urn:emisiowsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema targetNamespace="urn:emisiowsdl">
<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"
/>
<s:import namespace="http://schemas.xmlsoap.org/wsdl/" />
<s:complexType name="TIntegerList">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:TInteger[]"
ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"
/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:complexType name="TKeyValue">
<s:all>
<s:element name="key" type="s:string" />
<s:element name="value" type="s:string" />
</s:all>
</s:complexType>
<s:complexType name="TAssociativeArray">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:TKeyValue[]"
ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"
/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:complexType name="TAssociativeArrayList">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:TAssociativeArray[]"
ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"
/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:simpleType name="TString">
<s:restriction base="s:string" />
</s:simpleType>
<s:simpleType name="TInteger">
<s:restriction base="s:int" />
</s:simpleType>
<s:simpleType name="TFloat">
<s:restriction base="s:float" />
</s:simpleType>
</s:schema>
</types>
<message name="ObtenirPrimaTotal_ProjecteRequest">
<part name="Login" type="s0:TString" />
<part name="Password" type="s0:TString" />
<part name="CodiMediador" type="s0:TString" />
<part name="DataEfecte" type="s0:TString" />
<part name="DataVenciment" type="s0:TString" />
<part name="FormaPagament" type="s0:TString" />
<part name="LlistaModalitats" type="s0:TAssociativeArrayList" />
<part name="LlistaRiscs" type="s0:TAssociativeArrayList" />
<part name="LlistaClausules" type="s0:TIntegerList" />
</message>
<message name="ObtenirPrimaTotal_ProjecteResponse">
<part name="CodiError" type="s0:TString" />
<part name="TexteError" type="s0:TString" />
<part name="PrimaNeta" type="s0:TFloat" />
<part name="PrimaNetaImpostos" type="s0:TFloat" />
<part name="PrimaNetaTotalRebut" type="s0:TFloat" />
<part name="PrimaAnual" type="s0:TFloat" />
<part name="PrimaAnualImpostos" type="s0:TFloat" />
<part name="PrimaAnualTotalRebut" type="s0:TFloat" />
</message>
<portType name="emisiowsdlPortType">
<operation name="ObtenirPrimaTotal_Projecte">
<documentation>Retorna la prima d'una plissa</documentation>
<input message="s0:ObtenirPrimaTotal_ProjecteRequest" />
<output message="s0:ObtenirPrimaTotal_ProjecteResponse" />
</operation>
</portType>
<binding name="emisiowsdlBinding" type="s0:emisiowsdlPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
<operation name="ObtenirPrimaTotal_Projecte">
<soap:operation
soapAction="urn:emisiowsdl#ObtenirPrimaTotal_Proje cte" style="rpc" />
<input>
<soap:body use="encoded" namespace="urn:emisiowsdl"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:emisiowsdl"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="emisiowsdl">
<port name="emisiowsdlPort" binding="s0:emisiowsdlBinding">
<soap:address location="https://www.dummy.net:11110/WebService.php?webservice=emisio/server.php"
/>
</port>
</service>
</definitions>
************ WSDL ends here ***************
************ Response starts here ***********
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd" xmlns:tns="urn:emisiowsdl">
<SOAP-ENV:Body>
<ns1:ObtenirPrimaTotal_ProjecteResponse
xmlns:ns1="urn:emisiowsdl">
<CodiError xsi:type="tns:TString">
</CodiError>
<TexteError xsi:type="tns:TString">
</TexteError>
<PrimaNeta xsi:type="tns:TFloat">30.89</PrimaNeta>
<PrimaNetaImpostos
xsi:type="tns:TFloat">1.94</PrimaNetaImpostos>
<PrimaNetaTotalRebut
xsi:type="tns:TFloat">32.83</PrimaNetaTotalRebut>
<PrimaAnual xsi:type="tns:TFloat">30.81</PrimaAnual>
<PrimaAnualImpostos
xsi:type="tns:TFloat">1.94</PrimaAnualImpostos>
<PrimaAnualTotalRebut
xsi:type="tns:TFloat">32.75</PrimaAnualTotalRebut>
</ns1:ObtenirPrimaTotal_ProjecteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************ Response ends here ***********

************** Exception Text starts here **************
System.InvalidOperationException: There is an error in XML document
(1, 541). ---> System.InvalidCastException: Cannot assign object of
type System.Xml.XmlNode[] to an object of type System.String.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read5_ObtenirPrimaTotal_Projec teResponse()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)
at TestWrapperARAG.net.aragonline.www.emisiowsdl.ObtenirPrimaTotal_Projecte(String
Login, String Password, String CodiMediador, String DataEfecte, String
DataVenciment, String FormaPagament, TKeyValue[][] LlistaModalitats,
TKeyValue[][] LlistaRiscs, Int32[] LlistaClausules, String&
TexteError, Single& PrimaNeta, Single& PrimaNetaImpostos, Single&
PrimaNetaTotalRebut, Single& PrimaAnual, Single& PrimaAnualImpostos,
Single& PrimaAnualTotalRebut) in
d:\mtomas\projects\tarificador2.0\arag\testwrapper arag\referencias
web\net.aragonline.www\reference.cs:line 55
at TestWrapperARAG.Form1.button1_Click(Object sender, EventArgs e)
in d:\mtomas\projects\tarificador2.0\arag\testwrapper arag\form1.cs:line
134
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
************** Exception Text ends here **************
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi all!

I've found the problem! (but now I want the best solution! :( )

The types for the response parameters of the wsdl, are derivated from
the xsd types, TFloat, TString, ... If I manipulate the response
before deserialize and I replace "tns:TFloat" with "xsd:float" (and
"tns:TString" with "xsd:string", ....) the response is serialized
correctly by .NET, WHY?

So, I can use a SOAPExtension to replace the types before deserialize,
but it's a little dirty, isn't it!? Is there any better solution?

Thanks in advance,

Marc.

do**********@hotmail.com (Marc) wrote in message news:<8c**************************@posting.google. com>...
Hi!

I'm working with a C# client that calls a php web service. I've
created a wrapper to call the service using .NET wsdl tool (adding a
web reference).

The call to the server works fine, it is serialized correctly, and the
server returns a response (I've captured the response and it's
correct!) but when the .NET deserialize this response, it throws the
exception "System.InvalidOperationException: There is an error in XML
document (1, 541). ---> System.InvalidCastException: Cannot assign
object of type System.Xml.XmlNode[] to an object of type
System.String." (The full exception text is detailed at the end of the
message).

The particular thing of the web service operation is that uses input
and output parameters, perhaps that's the problem?

Can anybody helps me?

Thanks a lot in advance,

Marc.

************ WSDL starts here ***************
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="urn:emisiowsdl"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="urn:emisiowsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema targetNamespace="urn:emisiowsdl">
<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/"
/>
<s:import namespace="http://schemas.xmlsoap.org/wsdl/" />
<s:complexType name="TIntegerList">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:TInteger[]"
ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"
/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:complexType name="TKeyValue">
<s:all>
<s:element name="key" type="s:string" />
<s:element name="value" type="s:string" />
</s:all>
</s:complexType>
<s:complexType name="TAssociativeArray">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:TKeyValue[]"
ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"
/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:complexType name="TAssociativeArrayList">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:TAssociativeArray[]"
ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"
/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:simpleType name="TString">
<s:restriction base="s:string" />
</s:simpleType>
<s:simpleType name="TInteger">
<s:restriction base="s:int" />
</s:simpleType>
<s:simpleType name="TFloat">
<s:restriction base="s:float" />
</s:simpleType>
</s:schema>
</types>
<message name="ObtenirPrimaTotal_ProjecteRequest">
<part name="Login" type="s0:TString" />
<part name="Password" type="s0:TString" />
<part name="CodiMediador" type="s0:TString" />
<part name="DataEfecte" type="s0:TString" />
<part name="DataVenciment" type="s0:TString" />
<part name="FormaPagament" type="s0:TString" />
<part name="LlistaModalitats" type="s0:TAssociativeArrayList" />
<part name="LlistaRiscs" type="s0:TAssociativeArrayList" />
<part name="LlistaClausules" type="s0:TIntegerList" />
</message>
<message name="ObtenirPrimaTotal_ProjecteResponse">
<part name="CodiError" type="s0:TString" />
<part name="TexteError" type="s0:TString" />
<part name="PrimaNeta" type="s0:TFloat" />
<part name="PrimaNetaImpostos" type="s0:TFloat" />
<part name="PrimaNetaTotalRebut" type="s0:TFloat" />
<part name="PrimaAnual" type="s0:TFloat" />
<part name="PrimaAnualImpostos" type="s0:TFloat" />
<part name="PrimaAnualTotalRebut" type="s0:TFloat" />
</message>
<portType name="emisiowsdlPortType">
<operation name="ObtenirPrimaTotal_Projecte">
<documentation>Retorna la prima d'una plissa</documentation>
<input message="s0:ObtenirPrimaTotal_ProjecteRequest" />
<output message="s0:ObtenirPrimaTotal_ProjecteResponse" />
</operation>
</portType>
<binding name="emisiowsdlBinding" type="s0:emisiowsdlPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
<operation name="ObtenirPrimaTotal_Projecte">
<soap:operation
soapAction="urn:emisiowsdl#ObtenirPrimaTotal_Proje cte" style="rpc" />
<input>
<soap:body use="encoded" namespace="urn:emisiowsdl"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:emisiowsdl"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="emisiowsdl">
<port name="emisiowsdlPort" binding="s0:emisiowsdlBinding">
<soap:address location="https://www.dummy.net:11110/WebService.php?webservice=emisio/server.php"
/>
</port>
</service>
</definitions>
************ WSDL ends here ***************
************ Response starts here ***********
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd" xmlns:tns="urn:emisiowsdl">
<SOAP-ENV:Body>
<ns1:ObtenirPrimaTotal_ProjecteResponse
xmlns:ns1="urn:emisiowsdl">
<CodiError xsi:type="tns:TString">
</CodiError>
<TexteError xsi:type="tns:TString">
</TexteError>
<PrimaNeta xsi:type="tns:TFloat">30.89</PrimaNeta>
<PrimaNetaImpostos
xsi:type="tns:TFloat">1.94</PrimaNetaImpostos>
<PrimaNetaTotalRebut
xsi:type="tns:TFloat">32.83</PrimaNetaTotalRebut>
<PrimaAnual xsi:type="tns:TFloat">30.81</PrimaAnual>
<PrimaAnualImpostos
xsi:type="tns:TFloat">1.94</PrimaAnualImpostos>
<PrimaAnualTotalRebut
xsi:type="tns:TFloat">32.75</PrimaAnualTotalRebut>
</ns1:ObtenirPrimaTotal_ProjecteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************ Response ends here ***********

************** Exception Text starts here **************
System.InvalidOperationException: There is an error in XML document
(1, 541). ---> System.InvalidCastException: Cannot assign object of
type System.Xml.XmlNode[] to an object of type System.String.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read5_ObtenirPrimaTotal_Projec teResponse()
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)
at TestWrapperARAG.net.aragonline.www.emisiowsdl.ObtenirPrimaTotal_Projecte(String
Login, String Password, String CodiMediador, String DataEfecte, String
DataVenciment, String FormaPagament, TKeyValue[][] LlistaModalitats,
TKeyValue[][] LlistaRiscs, Int32[] LlistaClausules, String&
TexteError, Single& PrimaNeta, Single& PrimaNetaImpostos, Single&
PrimaNetaTotalRebut, Single& PrimaAnual, Single& PrimaAnualImpostos,
Single& PrimaAnualTotalRebut) in
d:\mtomas\projects\tarificador2.0\arag\testwrapper arag\referencias
web\net.aragonline.www\reference.cs:line 55
at TestWrapperARAG.Form1.button1_Click(Object sender, EventArgs e)
in d:\mtomas\projects\tarificador2.0\arag\testwrapper arag\form1.cs:line
134
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
************** Exception Text ends here **************

Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.