471,337 Members | 1,088 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

How to write custom serialization method in C# web service

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("exec uteCommandReturn",
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">000000000000000000001000d001 1000</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.000000000000000000001000 d0021000</principalGuid>
<sessionId
xsi:type="xsd:string">b29b1b304358680a017385bef29f 4efb-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

Nov 12 '05 #1
0 2083

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Demetri | last post: by
20 posts views Thread by Nikolay Petrov | last post: by
reply views Thread by CJ Taylor | last post: by
3 posts views Thread by Zachary Turner | last post: by
reply views Thread by Bob L. | last post: by
11 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.