How to write custom serialization method in C# web service
Question posted by: psy000@gmail.com
(Guest)
on
November 12th, 2005 05:08 AM
Hi,
I have a C# web service client that talks to a JAVA application sever.
I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy
stub c# code. When I try to use c# client connect to application
server, I did not get the result in the C# client side, I used a soap
monitor to look at the SOAP messages that were exchanged, I can see
server returned a correct SOAP message, but the C# client failed to
deserialize the XML result back to the C# object.
I wonder if there is a way to write a custom XML deserializer to
populate the result back to C# object. The serialization part seemed to
be ok.
The following is the proxy code generated by wsdl.exe:
public class CommandServerService :
System.Web.Services.Protocols.SoapHttpClientProtoc ol {
/// <remarks/>
public CommandServerService() {
this.Url = "http://localhost:7001/services/CommandServer";
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAt tribute("",
Use=System.Web.Services.Description.SoapBindingUse .Literal,
ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Bare)]
[return:
System.Xml.Serialization.XmlElementAttribute("executeCommandReturn",
Namespace="http://webservice.foo.com")]
public TargetableCommand
executeCommand([System.Xml.Serialization.XmlElementAttribute(Names pace="http://webservice.foo.com")]
string in0,
[System.Xml.Serialization.XmlElementAttribute(Names pace="http://webservice.foo.com")]
TargetCommand in1) {
object[] results = this.Invoke("executeCommand", new object[] {
in0,
in1});
return ((TargetCommand)(results[0]));
}
....
}
The elements of "results[0]" are null.I used "Document/Literal" style
in wsdl document. I can get the result[0] with correct values populated
when I use "RP C encoding" style.
The generated proxy code does not tell me how System.Xml.Serialization
is called to handle serialization/deserialization, it seems that .Net
handles it automatically. I wonder how I can overwrite this behavoir by
supplying a custom serialization/deserialization method to populate the
result[0] with returning values. The following is the XML document
returned by the server:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<executeCommandReturn xsi:type="ns1:LoginCommand"
xmlns="http://webservice.foo.com" xmlns:ns1="http://foo.bar.com">
<authenticationMethodId xsi:type="xsd:string"
xsi:nil="true"/>
<authenticationState
xsi:type="xsd:string">authenticated</authenticationState>
<authenticationStep xsi:type="xsd:string" xsi:nil="true"/>
<hiddenParameters
xsi:type="ns2:ArrayOf_tns5_AbstractParameterDTO"
xmlns:ns2="http://webservice.rsa.com"/>
<identitySourceGuid
xsi:type="xsd:string">000000000000000000001000d0011000</identitySourceGuid>
<message xsi:type="ns3:MessageDTO" xsi:nil="true"
xmlns:ns3="http://data.authn.rsa.com"/>
<netAddress xsi:nil="true"/>
<parameters
xsi:type="ns4:ArrayOf_tns5_AbstractParameterDTO"
xmlns:ns4="http://webservice.rsa.com"/>
<policyGuid xsi:type="xsd:string" xsi:nil="true"/>
<principalGuid
xsi:type="xsd:string">ims.000000000000000000001000d0021000</principalGuid>
<sessionId
xsi:type="xsd:string">b29b1b304358680a017385bef29f4efb-k0PBDzXeDhxF</sessionId>
<usingTransientSession
xsi:type="xsd:boolean">false</usingTransientSession>
</executeCommandReturn>
</soapenv:Body>
</soapenv:Envelope>
The values returned by the server are in the message, but the client
failed to deserialize the values into result[0], which is
"TargetCommand" objec.
I am new to C#, any advice is appricated.
Thanks
Reply
0
Answers Posted
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 196,829 network members.
Top Community Contributors
|