Loading ...
Sorry, an error occurred while loading the content.

Problem with J2ME, .net Web service and ksoap

Expand Messages
  • ellenghm
    Hi; i am currently interoperate the J2ME application and .net web service by using ksoap. i manage to get the simple response and display the string Hello
    Message 1 of 3 , Sep 18, 2003
    • 0 Attachment
      Hi;

      i am currently interoperate the J2ME application and .net web
      service by using ksoap.
      i manage to get the simple response and display the string "Hello
      World" from it. But, unfortunately, when i try to read array data
      from response, it failed! i had check that the response return me the
      array. when i try to cast the response data type from object to
      SoapObject in J2ME IDE, it give me error message as below:

      'java.lang.ClassCastException'

      Can somebody help me to solve it? The below is my code and soap
      request and response that i get.

      thanx & best regards.

      //====================================================================
      /* J2ME code */
      //====================================================================
      private Object callService(String methodName )
      {
      Object result = null;
      //String serviceUrl
      = "http://localhost/WebSrvKSoap/kSoapConn.asmx";
      //String serviceNamespace
      = "http://localhost/WebSrvKSoap/kSoapConn";
      //String soapAction
      = "http://localhost/WebSrvKSoap/kSoapConn/getSoapObjCol";

      try
      {
      request = new SoapObject( serviceNamespace,
      methodName );
      request.addProperty( "arg0", new Integer(0));

      transport = new HttpTransport( serviceUrl, soapAction
      + "#" + methodName );
      //transport = new HttpTransport( serviceUrl,
      soapAction );
      transport.debug = true;

      classMap = new ClassMap();
      //classMap.prefixMap = new PrefixMap(
      classMap.prefixMap, "getSoapObjCol", serviceNamespace );
      classMap.prefixMap = new PrefixMap(
      classMap.prefixMap, "air", serviceNamespace );
      transport.setClassMap( classMap );

      result = transport.call( request );
      }
      catch( Exception e )
      {
      e.printStackTrace();
      System.out.println( "Request: \n" +
      transport.requestDump );
      System.out.println( "Response: \n" +
      transport.responseDump );
      System.out.println(e);
      result = null;
      }//end try/catch

      return result;
      }//end callService()

      public void commandAction(javax.microedition.lcdui.Command c,
      javax.microedition.lcdui.Displayable d) {
      try
      {
      if(c.equals(okCmd))
      {
      Object cSR;
      cSR = callService("getSoapObjCol");
      SoapObject objResult = (SoapObject) cSR; //service
      call
      if ( objResult != null )
      {
      resultItem.setText("The weather at " +
      objResult.getProperty(0));
      }//end if ( objResult != null )
      else
      {
      resultItem.setText("Nothing");
      }
      }

      else if(c.equals(exitCmd))
      {
      destroyApp(false);
      notifyDestroyed();
      }
      }
      catch (Exception e)
      {
      e.printStackTrace();
      resultItem.setLabel("Error: " + e);
      System.out.println(e);
      }
      }

      //====================================================================
      /* Soap request */
      //====================================================================
      "\r\n<SOAP-ENV:Envelope
      xmlns:getSoapObjCol=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
      xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
      xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"
      xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n
      <SOAP-ENV:Body SOAP-
      ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n
      <getSoapObjCol:getSoapObjCol id=\"o0\" SOAP-ENC:root=\"1\" />\r\n
      </SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>\r\n"

      //====================================================================
      /* Soap response */
      //====================================================================
      "<?xml version=\"1.0\" encoding=\"utf-8\"?>
      <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/
      \"
      xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"
      xmlns:tns=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
      xmlns:types=\"http://192.168.0.192/WebSrvKSoap/kSoapConn/encod
      edTypes\"
      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
      xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
      <soap:Body
      soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
      <tns:getSoapObjColResponse>
      <getSoapObjColResult href=\"#id1\" />
      </tns:getSoapObjColResponse>
      <soapenc:Array id=\"id1\"
      soapenc:arrayType=\"types:soapObj[2]\">
      <Item href=\"#id2\" />
      <Item href=\"#id3\" />
      </soapenc:Array>
      <types:soapObj id=\"id2\"
      xsi:type=\"types:soapObj\">
      <Name
      xsi:type=\"xsd:string\">susan</Name>
      <ID xsi:type=\"xsd:int\">1</ID>
      </types:soapObj>
      <types:soapObj id=\"id3\"
      xsi:type=\"types:soapObj\">
      <Name
      xsi:type=\"xsd:string\">cheng</Name>
      <ID xsi:type=\"xsd:int\">2</ID>
      </types:soapObj>
      </soap:Body>
      </soap:Envelope>"
    • Stefan Haustein
      ... kSOAP should return an instance of Vector. The adress of the ksoap mailing list is ksoap@enhydra.org, you can subscribe and view the archive at
      Message 2 of 3 , Sep 19, 2003
      • 0 Attachment
        ellenghm wrote:

        >
        > i am currently interoperate the J2ME application and .net web
        > service by using ksoap.
        > i manage to get the simple response and display the string "Hello
        > World" from it. But, unfortunately, when i try to read array data
        > from response, it failed! i had check that the response return me the
        > array. when i try to cast the response data type from object to
        > SoapObject in J2ME IDE, it give me error message as below:
        >
        > 'java.lang.ClassCastException'
        >
        > Can somebody help me to solve it? The below is my code and soap
        > request and response that i get.

        kSOAP should return an instance of Vector. The adress of the ksoap
        mailing list is ksoap@..., you can subscribe and view the
        archive at http://ksoap.enhydra.org/project/mailingLists/index.html

        Cheers,
        Stefan

        >
        > thanx & best regards.
        >
        > //====================================================================
        > /* J2ME code */
        > //====================================================================
        > private Object callService(String methodName )
        > {
        > Object result = null;
        > //String serviceUrl
        > = "http://localhost/WebSrvKSoap/kSoapConn.asmx";
        > //String serviceNamespace
        > = "http://localhost/WebSrvKSoap/kSoapConn";
        > //String soapAction
        > = "http://localhost/WebSrvKSoap/kSoapConn/getSoapObjCol";
        >
        > try
        > {
        > request = new SoapObject( serviceNamespace,
        > methodName );
        > request.addProperty( "arg0", new Integer(0));
        >
        > transport = new HttpTransport( serviceUrl, soapAction
        > + "#" + methodName );
        > //transport = new HttpTransport( serviceUrl,
        > soapAction );
        > transport.debug = true;
        >
        > classMap = new ClassMap();
        > //classMap.prefixMap = new PrefixMap(
        > classMap.prefixMap, "getSoapObjCol", serviceNamespace );
        > classMap.prefixMap = new PrefixMap(
        > classMap.prefixMap, "air", serviceNamespace );
        > transport.setClassMap( classMap );
        >
        > result = transport.call( request );
        > }
        > catch( Exception e )
        > {
        > e.printStackTrace();
        > System.out.println( "Request: \n" +
        > transport.requestDump );
        > System.out.println( "Response: \n" +
        > transport.responseDump );
        > System.out.println(e);
        > result = null;
        > }//end try/catch
        >
        > return result;
        > }//end callService()
        >
        > public void commandAction(javax.microedition.lcdui.Command c,
        > javax.microedition.lcdui.Displayable d) {
        > try
        > {
        > if(c.equals(okCmd))
        > {
        > Object cSR;
        > cSR = callService("getSoapObjCol");
        > SoapObject objResult = (SoapObject) cSR; //service
        > call
        > if ( objResult != null )
        > {
        > resultItem.setText("The weather at " +
        > objResult.getProperty(0));
        > }//end if ( objResult != null )
        > else
        > {
        > resultItem.setText("Nothing");
        > }
        > }
        >
        > else if(c.equals(exitCmd))
        > {
        > destroyApp(false);
        > notifyDestroyed();
        > }
        > }
        > catch (Exception e)
        > {
        > e.printStackTrace();
        > resultItem.setLabel("Error: " + e);
        > System.out.println(e);
        > }
        > }
        >
        > //====================================================================
        > /* Soap request */
        > //====================================================================
        > "\r\n<SOAP-ENV:Envelope
        > xmlns:getSoapObjCol=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
        > xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
        > xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
        > xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"
        > xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n
        > <SOAP-ENV:Body SOAP-
        > ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n
        > <getSoapObjCol:getSoapObjCol id=\"o0\" SOAP-ENC:root=\"1\" />\r\n
        > </SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>\r\n"
        >
        > //====================================================================
        > /* Soap response */
        > //====================================================================
        > "<?xml version=\"1.0\" encoding=\"utf-8\"?>
        > <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/
        > \"
        > xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"
        > xmlns:tns=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
        > xmlns:types=\"http://192.168.0.192/WebSrvKSoap/kSoapConn/encod
        > edTypes\"
        > xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
        > xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
        > <soap:Body
        > soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
        > <tns:getSoapObjColResponse>
        > <getSoapObjColResult href=\"#id1\" />
        > </tns:getSoapObjColResponse>
        > <soapenc:Array id=\"id1\"
        > soapenc:arrayType=\"types:soapObj[2]\">
        > <Item href=\"#id2\" />
        > <Item href=\"#id3\" />
        > </soapenc:Array>
        > <types:soapObj id=\"id2\"
        > xsi:type=\"types:soapObj\">
        > <Name
        > xsi:type=\"xsd:string\">susan</Name>
        > <ID xsi:type=\"xsd:int\">1</ID>
        > </types:soapObj>
        > <types:soapObj id=\"id3\"
        > xsi:type=\"types:soapObj\">
        > <Name
        > xsi:type=\"xsd:string\">cheng</Name>
        > <ID xsi:type=\"xsd:int\">2</ID>
        > </types:soapObj>
        > </soap:Body>
        > </soap:Envelope>"
        >
        >
        >
        > -----------------------------------------------------------------
        > This group is a forum for builders of SOAP implementations to discuss implementation and interoperability issues. Please stay on-topic.
        >
        > To unsubscribe from this group, send an email to:
        > soapbuilders-unsubscribe@yahoogroups.com
        >
        >
        >
        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
        >
      • ellenghm
        hi; thanx for your reply. i finally get it works! But now, i am facing another problem. i am getting response from .net web service as below:
        Message 3 of 3 , Sep 24, 2003
        • 0 Attachment
          hi;
          thanx for your reply. i finally get it works!
          But now, i am facing another problem.

          i am getting response from .net web service as below:

          "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope
          xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
          xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"
          xmlns:tns=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
          xmlns:types=\"http://192.168.0.192/WebSrvKSoap/kSoapConn/encodedTypes\
          " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
          xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body
          soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/
          \"><tns:getSoapObjColResponse><getSoapObjColResult href=\"#id1
          \" /></tns:getSoapObjColResponse><soapenc:Array id=\"id1\"
          soapenc:arrayType=\"xsd:anyType[4]\"><Item
          xsi:type=\"xsd:base64Binary\">iVBORw0KGgoAAAANSUhEUgAAAAYAAAAICAIAAABV
          pBlvAAAAAXNSR0IArs4c6QAAAARnQU1BAACx\r\njwv8YQUAAAAgY0hSTQAAeiYAAICEAA
          D6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlz\r\nAAAuIwAALiMBeKU/dgAA
          ABVJREFUGFdjZHLvYEADQCE0xEB3IQBN5CMdi4VHgQAAAABJRU5ErkJg\r\nggAAAAAAAA
          AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n
          AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</Item><Item
          xsi:type=\"xsd:string\">Testing 123</Item><Item
          xsi:type=\"xsd:int\">2383</Item><Item
          xsi:type=\"xsd:string\">C:\\3.jpg</Item></soapenc:Array></soap:Body></
          soap:Envelope>"

          when i try to map the response with marshalbase64, it return me
          null value. How can i solve it? the below is code in J2ME:

          "ByteArrayInputStream bis = new ByteArrayInputStream (str.getBytes
          ());
          InputStreamReader reader = new InputStreamReader
          (bis);
          XmlParser xp = new XmlParser (reader);
          // Use default mapping between Java objects and Soap
          elements;

          ClassMap cm = new ClassMap(Soap.VER12);
          //Marshal ms = new MarshalBase64();
          Marshal ms = new MarshalDate();
          ms.register(cm);
          SoapEnvelope envelope = new SoapEnvelope (cm);
          envelope.parse (xp);

          SoapObject obj = (SoapObject) envelope.getResult();
          "
          hope i can get the reply soon.
          thanx and best regards.


          --- In soapbuilders@yahoogroups.com, Stefan Haustein <haustein@k...>
          wrote:
          > ellenghm wrote:
          >
          > >
          > > i am currently interoperate the J2ME application and .net web
          > > service by using ksoap.
          > > i manage to get the simple response and display the
          string "Hello
          > > World" from it. But, unfortunately, when i try to read array data
          > > from response, it failed! i had check that the response return me
          the
          > > array. when i try to cast the response data type from object to
          > > SoapObject in J2ME IDE, it give me error message as below:
          > >
          > > 'java.lang.ClassCastException'
          > >
          > > Can somebody help me to solve it? The below is my code and
          soap
          > > request and response that i get.
          >
          > kSOAP should return an instance of Vector. The adress of the ksoap
          > mailing list is ksoap@e..., you can subscribe and view the
          > archive at http://ksoap.enhydra.org/project/mailingLists/index.html
          >
          > Cheers,
          > Stefan
          >
          > >
          > > thanx & best regards.
          > >
          >
          > //==================================================================
          ==
          > > /* J2ME code */
          >
          > //==================================================================
          ==
          > > private Object callService(String methodName )
          > > {
          > > Object result = null;
          > > //String serviceUrl
          > > = "http://localhost/WebSrvKSoap/kSoapConn.asmx";
          > > //String serviceNamespace
          > > = "http://localhost/WebSrvKSoap/kSoapConn";
          > > //String soapAction
          > > = "http://localhost/WebSrvKSoap/kSoapConn/getSoapObjCol";
          > >
          > > try
          > > {
          > > request = new SoapObject( serviceNamespace,
          > > methodName );
          > > request.addProperty( "arg0", new Integer(0));
          > >
          > > transport = new HttpTransport( serviceUrl,
          soapAction
          > > + "#" + methodName );
          > > //transport = new HttpTransport( serviceUrl,
          > > soapAction );
          > > transport.debug = true;
          > >
          > > classMap = new ClassMap();
          > > //classMap.prefixMap = new PrefixMap(
          > > classMap.prefixMap, "getSoapObjCol", serviceNamespace );
          > > classMap.prefixMap = new PrefixMap(
          > > classMap.prefixMap, "air", serviceNamespace );
          > > transport.setClassMap( classMap );
          > >
          > > result = transport.call( request );
          > > }
          > > catch( Exception e )
          > > {
          > > e.printStackTrace();
          > > System.out.println( "Request: \n" +
          > > transport.requestDump );
          > > System.out.println( "Response: \n" +
          > > transport.responseDump );
          > > System.out.println(e);
          > > result = null;
          > > }//end try/catch
          > >
          > > return result;
          > > }//end callService()
          > >
          > > public void commandAction(javax.microedition.lcdui.Command c,
          > > javax.microedition.lcdui.Displayable d) {
          > > try
          > > {
          > > if(c.equals(okCmd))
          > > {
          > > Object cSR;
          > > cSR = callService("getSoapObjCol");
          > > SoapObject objResult = (SoapObject)
          cSR; //service
          > > call
          > > if ( objResult != null )
          > > {
          > > resultItem.setText("The weather at " +
          > > objResult.getProperty(0));
          > > }//end if ( objResult != null )
          > > else
          > > {
          > > resultItem.setText("Nothing");
          > > }
          > > }
          > >
          > > else if(c.equals(exitCmd))
          > > {
          > > destroyApp(false);
          > > notifyDestroyed();
          > > }
          > > }
          > > catch (Exception e)
          > > {
          > > e.printStackTrace();
          > > resultItem.setLabel("Error: " + e);
          > > System.out.println(e);
          > > }
          > > }
          > >
          >
          > //==================================================================
          ==
          > > /* Soap request */
          >
          > //==================================================================
          ==
          > > "\r\n<SOAP-ENV:Envelope
          > >
          xmlns:getSoapObjCol=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
          > > xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
          > > xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
          > > xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"
          > > xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n
          > > <SOAP-ENV:Body SOAP-
          > > ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/
          \">\r\n
          > > <getSoapObjCol:getSoapObjCol id=\"o0\" SOAP-ENC:root=\"1\" />\r\n
          > > </SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>\r\n"
          > >
          >
          > //==================================================================
          ==
          > > /* Soap response */
          >
          > //==================================================================
          ==
          > > "<?xml version=\"1.0\" encoding=\"utf-8\"?>
          > > <soap:Envelope
          xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/
          > > \"
          > > xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"
          > > xmlns:tns=\"http://192.168.0.192/WebSrvKSoap/kSoapConn\"
          > > xmlns:types=\"http://192.168.0.192/WebSrvKSoap/kSoapConn/encod
          > > edTypes\"
          > > xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
          > > xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
          > > <soap:Body
          > > soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
          > > <tns:getSoapObjColResponse>
          > > <getSoapObjColResult href=\"#id1\" />
          > > </tns:getSoapObjColResponse>
          > > <soapenc:Array id=\"id1\"
          > > soapenc:arrayType=\"types:soapObj[2]\">
          > > <Item href=\"#id2\" />
          > > <Item href=\"#id3\" />
          > > </soapenc:Array>
          > > <types:soapObj id=\"id2\"
          > > xsi:type=\"types:soapObj\">
          > > <Name
          > > xsi:type=\"xsd:string\">susan</Name>
          > > <ID xsi:type=\"xsd:int\">1</ID>
          > > </types:soapObj>
          > > <types:soapObj id=\"id3\"
          > > xsi:type=\"types:soapObj\">
          > > <Name
          > > xsi:type=\"xsd:string\">cheng</Name>
          > > <ID xsi:type=\"xsd:int\">2</ID>
          > > </types:soapObj>
          > > </soap:Body>
          > > </soap:Envelope>"
          > >
          > >
          > >
          > > -----------------------------------------------------------------
          > > This group is a forum for builders of SOAP implementations to
          discuss implementation and interoperability issues. Please stay on-
          topic.
          > >
          > > To unsubscribe from this group, send an email to:
          > > soapbuilders-unsubscribe@yahoogroups.com
          > >
          > >
          > >
          > > Your use of Yahoo! Groups is subject to
          http://docs.yahoo.com/info/terms/
          > >
          > >
        Your message has been successfully submitted and would be delivered to recipients shortly.