Results 1 to 2 of 2

Thread: [RESOLVED] ksoap2 problem

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Resolved [RESOLVED] ksoap2 problem

    Hi, I'm kind of new to Android development, and i'm having some trouble with some code. I'm trying to reach some webservices using ksoap2 but the Call method is giving me some headaches..

    Here's the code I'm using.

    Code:
    import org.ksoap2.*;
    import org.ksoap2.serialization.KvmSerializable;
    import org.ksoap2.serialization.Marshal;
    import org.ksoap2.serialization.PropertyInfo;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;
    
    (...)
    
    	private static final String NAMESPACE = "http://192.168.10.1:9998/";
        private static final String URL = "http://192.168.10.1:9998/updatetabelas.asmx";
        private static final String GET_INTREBARE = "HelloWorld";
    
    
        private void msgbox(String __title, String __message){
        	AlertDialog.Builder __msg=new AlertDialog.Builder(BaseDadosActivity.this);
        	__msg.setTitle(__title);
        	__msg.setMessage(__message);
        	__msg.setNeutralButton("Ok", null);
        	__msg.show();
        }
    
        public void callHello()
        {
        	try {
        		 
                SoapSerializationEnvelope env = new SoapSerializationEnvelope(
                        SoapEnvelope.VER12);
     
                env.dotNet = true;
                env.xsd = SoapSerializationEnvelope.XSD;
                env.enc = SoapSerializationEnvelope.ENC;
                
                SoapObject request = new SoapObject(NAMESPACE, "HelloWorld");
                env.setOutputSoapObject(request);
    
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.call("", env);
                SoapObject result = (SoapObject) env.getResponse();
                
                msgbox("Result", result.toString());
                
            } catch (Exception e) {
            	 e.getStackTrace();
            }
     
        }
    androidHttpTransport.call throws an exception with empty Message. I can't understand why.
    Also i added to the Manifest
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    If needed, I will provide public IP address for testing purposes by private message.

    XML
    Code:
    SOAP 1.1
    
    POST /updatetabelas.asmx HTTP/1.1
    Host: 192.168.10.1
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://192.168.10.1:9998/HelloWorld"
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <HelloWorld xmlns="http://192.168.10.1:9998/" />
      </soap:Body>
    </soap:Envelope>
    
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <HelloWorldResponse xmlns="http://192.168.10.1:9998/">
          <HelloWorldResult>string</HelloWorldResult>
        </HelloWorldResponse>
      </soap:Body>
    </soap:Envelope>
    
    SOAP 1.2
    
    Segue-se um exemplo de pedido e resposta SOAP 1.2. &#201; necess&#225;rio substituir os marcadores de posi&#231;&#227;o mostrados por valores reais.
    
    POST /updatetabelas.asmx HTTP/1.1
    Host: 192.168.10.1
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <HelloWorld xmlns="http://192.168.10.1:9998/" />
      </soap12:Body>
    </soap12:Envelope>
    
    HTTP/1.1 200 OK
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <HelloWorldResponse xmlns="http://192.168.10.1:9998/">
          <HelloWorldResult>string</HelloWorldResult>
        </HelloWorldResponse>
      </soap12:Body>
    </soap12:Envelope>
    Last edited by TDQWERTY; Jul 8th, 2012 at 03:32 PM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: ksoap2 problem

    Code is fine, problem is that network IO on the UI thread on Honeycombe is now allowed.

    solved using
    Code:
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width