kSOAP2 client on Android for accessing a JAX-WS service

Put your problem here if it does not fit any of the other categories.

kSOAP2 client on Android for accessing a JAX-WS service

Postby test_1234 » Fri Oct 01, 2010 4:27 pm

Hello everybody,

I'm struggle to solve the following problem.
I have a working JAX-WS service and I would like to access it from android emulator. After I done a research I decide it to use kSOAP2 package. I developed the client starting from some examples found it over the Internet (Temperature Converter I tested it on my emulator and worked fine). Here is a sniped form my client code:

Code: Select all
   final String SOAP_ACTION = "getMedia";
         final String METHOD_NAME = "getMedia";
         final String NAMESPACE = "http://my_name_space";

         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
         
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
               SoapEnvelope.VER11);
         // envelope.dotNet = true;
         envelope.setOutputSoapObject(request);

         AndroidHttpTransport ath = new AndroidHttpTransport(current);
         try {
            ath.call(SOAP_ACTION, envelope);
            String soapRes = envelope.bodyIn.toString();

            result.setText("RESULT: "+soapRes);

         } catch (Exception e) {
            // TODO: handle exception
            result.setText("Error: " + e.getMessage());
         


The error that I got on the emulator is:
Code: Select all
Expected: END_TAG{http://schemas.xmlsoap.org/soap/envelope/}Body:(position END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:317 in java.io.nputStreamReader@43e59d78


The SOAP messages exchanged (captured using TCP Monitor from AXIS):
Code: Select all
POST /ServFact/servFact HTTP/1.1
user-agent: kSOAP/2.0
soapaction: getMedia
content-type: text/xml
connection: close
content-length: 337
Host: 127.0.0.1:8081

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
   <v:Header />
   <v:Body>
      <n0:getMedia id="o0" c:root="1" xmlns:n0="http://my_name_space/" />
   </v:Body></v:Envelope>

=====RESPONSE========
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Date: Fri, 01 Oct 2010 15:03:45 GMT
Connection: close

<?xml version='1.0' encoding='UTF-8'?>
   <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
         <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
            <faultcode>S:Client</faultcode>
            <faultstring>Cannot find dispatch method for {http://my_name_space/}getMedia</faultstring>
         </S:Fault>
      </S:Body>
   </S:Envelope>


The log on the server side is:
Code: Select all
Oct 1, 2010 4:03:45 PM com.sun.xml.ws.transport.http.HttpAdapter fixQuotesAroundSoapAction                                                                   
WARNING: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: getMedia 


If I'm using the client made in Java for my service, everything works well. I notice a difference in the SOAP body request message:
Code: Select all
==== Request ====
POST /ServFact/servFact HTTP/1.1
Content-type: text/xml;charset="utf-8"
Soapaction: "getMedia"
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: JAX-WS RI 2.1.6 in JDK 6
Host: 127.0.0.1:8081
Connection: keep-alive
Content-Length: 116

<?xml version="1.0" ?>
   <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body></S:Body>
   </S:Envelope>

comparably with the one send it by the kSOAP2 where I have:
Code: Select all
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
   <v:Header />
   <v:Body>
    <n0:getMedia id="o0" c:root="1" xmlns:n0="http://my_name_space/" />
   </v:Body></v:Envelope>


The method that i need to invoke is called "getMedia()" with no arguments ant returns an ComplexType from a schema imported in WSDL.

Could someone give a hint how to solve this problem?

Looking forward to hearing from you soon!

Thank you!

-Daniel
test_1234
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 01, 2010 3:54 pm

Top

Re: kSOAP2 client on Android for accessing a JAX-WS service

Postby prudhviv » Wed Nov 24, 2010 11:17 am

hi Daniel,

Are you able to resolve the issue. I am also facing the same issue. Can you please help if you have the solution.

Thanks,
Prudhvi
prudhviv
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Nov 24, 2010 11:15 am

Re: kSOAP2 client on Android for accessing a JAX-WS service

Postby test_1234 » Thu Nov 25, 2010 1:01 pm

prudhviv wrote:hi Daniel,

Are you able to resolve the issue. I am also facing the same issue. Can you please help if you have the solution.

Thanks,
Prudhvi


I've just give up using the kSOAP2 package.
From what I remember on that time, what I've done was something like: buid a simple HTTP Java client and I construct my self the entire SOAP message (a simple string) an post it on the wire.

a snipped of the code:
Code: Select all
public static InputStream callServer(String sOAPACTION, String sOAPBody, String uri) {
      // TODO Auto-generated method stub
      InputStream result = null;
      DefaultHttpClient httpC = new DefaultHttpClient();
      HttpProtocolParams.setUseExpectContinue(httpC.getParams(), false);

      HttpPost httpPost = new HttpPost(uri);
      httpPost.setHeader("Content-Type", "text/xml; charset=\"utf-8\"");
      httpPost.setHeader("Soapaction", sOAPACTION);

      try {
         org.apache.http.HttpEntity entity = new org.apache.http.entity.StringEntity(
               sOAPBody);
         httpPost.setEntity(entity);
         org.apache.http.HttpResponse response = httpC.execute(httpPost);
         org.apache.http.HttpEntity r_entity = response.getEntity();
         if (r_entity != null) {
            return result = r_entity.getContent();
         }
      } catch (Exception e) {
         Log.v("Exception!:", e.getMessage());
      }
      httpC.getConnectionManager().shutdown();
      return result;
   }



Hope that helps.
test_1234
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 01, 2010 3:54 pm

Re: kSOAP2 client on Android for accessing a JAX-WS service

Postby aromanocohen » Wed Mar 07, 2012 4:29 am

I have solved your problem.

You need to do something like this in your code when specifying your Soap Action:

Code: Select all
conexionHttpUrl.setRequestProperty("SOAPAction", "\"MySoapAction\"");


The BackSlash (\) will quote the SoapAction and the Warning will stop appearing.
aromanocohen
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 07, 2012 4:25 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 22 guests