Porting Apache-SOAP java client into C# 
Author Message
 Porting Apache-SOAP java client into C#

Hi forks,

Is there anyone succeeded porting Apache-SOAP java client into C#
client?  In my situation, I'd like to make a C# client which
communicates with Apache-SOAP webservice.

So, I'm trying to port the 'addressbook' sample project which included
in Apache-SOAP 2.3, based on the article "A C# SOAP Apache Client"
( http://www.*-*-*.com/ )
However, there are little difference:  a SOAP message in 'addressbook'
sample project describes nested class;  while primitive types (e.g.
string) found in the latter example.

Following is the source code of GetAddress.cs(written by me), which is
the counterpart of GetAddress.java in 'addressbook' sample project:

namespace samples.addressbook
{
        using System;
        using System.Diagnostics;
        using System.Xml;
        using System.Xml.Serialization;
        using System.Web.Services;
        using System.Web.Services.Protocols;

        [System.Web.Services.WebServiceBindingAttribute(Name="urn:ItemManager",Namespace=
                 "http://localhost:8080/soap/servlet/rpcrouter")]
        [System.Xml.Serialization.SoapIncludeAttribute(typeof(Address))]
        [System.Xml.Serialization.SoapIncludeAttribute(typeof(PhoneNumber))]
        public class GetAddress:
System.Web.Services.Protocols.SoapHttpClientProtocol
        {
                public GetAddress()
                {
                        this.Url = "http://localhost:8080/soap/servlet/rpcrouter";
                }

                [System.Web.Services.Protocols.SoapDocumentMethodAttribute
                         ("",RequestNamespace="urn:AddressFetcher",ResponseNamespace="urn:AddressFetcher",
                         Use=System.Web.Services.Description.SoapBindingUse.Encoded,ParameterStyle=
                        System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
                public string getAddressFromName(string name)
                {
                        object [] results = null;
                        try
                        {
                                results = (Address [])(this.Invoke("getAddressFromName",new
object[] {name} ));
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("Generic Exception Handler: {0}", e.ToString());
                        }
                        return ((string)(results.ToString()));
                }

                public static void  Main(System.String[] args)
                {
                        GetAddress getAddress = new GetAddress();
                        Console.WriteLine((string)getAddress.getAddressFromName("John B.
Good"));
                }
        }

Quote:
}

Anyway above code doesn't work... error messages are:
Generic Exception Handler: System.InvalidOperationException: There is
an error in XML document (16,10). ---> System.InvalidCastException:
Cannot assign object of type System.Xml.XmlNode[] to an object of type
System.String.
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read5_getAddressFromName
Response()
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
   at samples.addressbook.GetAddress.getAddressFromName(String name)

And these are the SOAP request/response for above case:
POST /soap/servlet/rpcrouter HTTP/1.1User-Agent: Mozilla/4.0
(compatible; MSIE 6.0; MS Web Services Client Protocol
1.0.3705.0)Content-Type: text/xml; charset=utf-8SOAPAction:
""Content-Length: 624Expect: 100-continueConnection: Keep-AliveHost:
147.6.68.59<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap=" http://www.*-*-*.com/ ;
xmlns:soapenc=" http://www.*-*-*.com/ ;
xmlns:tns=" http://www.*-*-*.com/ :8070/soap/servlet/rpcrouter"
xmlns:types=" http://www.*-*-*.com/ :8070/soap/servlet/rpcrouter/encodedTypes"
xmlns:xsi=" http://www.*-*-*.com/ ;
xmlns:xsd=" http://www.*-*-*.com/ ;><soap:Body
soap:encodingStyle=" http://www.*-*-*.com/ ;><q1:getAddressFromName
xmlns:q1="urn:AddressFetcher"><name xsi:type="xsd:string">John B.
Good</name></q1:getAddressFromName></soap:Body></soap:Envelope>

HTTP/1.1 100 ContinueHTTP/1.1 200 OKContent-Type: text/xml;
charset=utf-8Content-Length: 927Date: Thu, 20 Jun 2002 12:46:41
GMTServer: Apache Tomcat/4.0.3 (HTTP/1.1 Connector)Set-Cookie:
JSESSIONID=8A804F1F89F3851DC8196F3D00D1F7DE;Path=/soap<?xml
version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope
xmlns:SOAP-ENV=" http://www.*-*-*.com/ ;
xmlns:xsi=" http://www.*-*-*.com/ ;
xmlns:xsd=" http://www.*-*-*.com/ ;>
<SOAP-ENV:Body>
<ns1:getAddressFromNameResponse xmlns:ns1="urn:AddressFetcher"
SOAP-ENV:encodingStyle=" http://www.*-*-*.com/ ;>
<return xmlns:ns2="urn:xml-soap-address-demo" xsi:type="ns2:address">
<phoneNumber xsi:type="ns2:phone">
<exchange xsi:type="xsd:string">456</exchange>
<areaCode xsi:type="xsd:int">123</areaCode>
<number xsi:type="xsd:string">7890</number>
</phoneNumber>
<zip xsi:type="xsd:int">12345</zip>
<streetNum xsi:type="xsd:int">123</streetNum>
<streetName xsi:type="xsd:string">Main Street</streetName>
<state xsi:type="xsd:string">NY</state>
<city xsi:type="xsd:string">Anytown</city>
</return>
</ns1:getAddressFromNameResponse>

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Can anyone give me a hint?

Koo Min



Mon, 06 Dec 2004 21:02:18 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Getting Microsoft SOAP to work with an Apache SOAP server

2. Q: calling Java SOAP services from C# : example?

3. Where to start for a C# SOAP Client....

4. C# as a SOAP client

5. Porting Java Apps To C#

6. java to C# and C# to java converters

7. Interoperability of C# webservice with Java Client

8. Can C# client talk to a Java server ??

9. ATL Soap Client bugs

10. VC7 - ATL Soap Client

11. Need help building a .NET soap client for XML for Analysis server

12. generic Soap webservice proxy client

 

 
Powered by phpBB® Forum Software