1

i have been trying to call a simple .NET webservice (HelloWorld) via android using ksoap2 ( i already tried and succeeded for a different webservice) . but this one requires an authentication so i searched how to add a header for the authentication , but still , i have no result returned in my textview.

SoapObject Request = new SoapObject(NAMESPACE,METHOD_NAME);  
List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
headers.add(new HeaderProperty("Authorization", "Basic"+Base64.encode("Username:Password".getBytes())));


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(Request);

        HttpTransportSE aht = new HttpTransportSE(URL);


        try{
            aht.call(SOAP_ACTION,envelope,headers);
            SoapPrimitive resultString = (SoapPrimitive)envelope.getResponse();

            tv.setText("yo :" + resultString);

        }
    catch(Exception e){
        e.printStackTrace();
    }

I have also an error in my Log :

ERROR : Thread Attached failed , but i don' think it's the source of

here is the wsdl for the HelloWorld method :

>     <wsdl:types>
>     <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
>     <s:element name="HelloWorld">
>     <s:complexType/>
>     </s:element>
>     <s:element name="HelloWorldResponse">
>     <s:complexType>
>     <s:sequence>
>     <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string"/>
>     </s:sequence>
>     </s:complexType>
>     </s:element>

my problem. Have anyone encountered this kind of problem , or my code is wrong at some point ?

Labraiki
  • 11
  • 5

2 Answers2

0

Try this:

 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);    
request.addProperty("requst_name",request_value);//if you have any request add here..                   
 envelope.setOutputSoapObject(request);
 envelope.implicitTypes = true;
 envelope1.dotNet = true;
 int Timeout = 60000;
 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, Timeout);
 androidHttpTransport.debug = true;
                try {

                    androidHttpTransport.call(SOAP_ACTION, envelope);
                    Object response = envelope.getResponse();
                    String res=response.toString();
                    }

                    }catch (XmlPullParserException e) {

                        e.printStackTrace();
                    } catch (SocketTimeoutException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
Android_coder
  • 9,953
  • 3
  • 17
  • 23
  • i tried your code , but no result either , no exceptioon caught , it seems that the code is fine , but my textview doesn't display the result . i tried to set my textview to test it inside me try catch block: tv.setText("yo :"); and it still display just textview when i launch the app , what does it mean ? – Labraiki Feb 18 '13 at 12:08
  • can you post your wsdl file – Android_coder Feb 18 '13 at 12:08
  • Okey , i add it to my question – Labraiki Feb 18 '13 at 12:16
  • have you print this String res=response.toString();? – Android_coder Feb 18 '13 at 12:23
  • in mine no , but when i used your code i did . how can u explain that even when i set : tv.setText("yo :") it wasn't displayed , it's like the try catch block is ignored ! – Labraiki Feb 18 '13 at 12:25
  • used this code System.out.println("Result: "+res); after this line String res=response.toString(); – Android_coder Feb 18 '13 at 12:26
  • Nothing about res is diplayed in the console ! – Labraiki Feb 18 '13 at 12:36
  • Object response = envelope.getResponse(); replace this line into SoapObject response = (SoapObject)envelope.bodyIn; – Android_coder Feb 18 '13 at 13:06
  • can u give me your email so i can send you this ? ( cause u'll need my login and password ) – Labraiki Feb 18 '13 at 13:42
  • couldn't fint it . anyway here is the details http://demo.digiparc.com/autocomplete.asmx login : mLabraiki pass: 123456 – Labraiki Feb 18 '13 at 13:50
  • I used some logs , apperntely the problem is in this line : aht.call(SOAP_ACTION,envelope); i catched an exeption too : org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @1:6 in java.io.InputStreamReader@45f9a5d0) – Labraiki Feb 18 '13 at 16:34
0

.This is how I access .net web service. In my case i am sending 2 parameters username and password , where the service will return a string according to the database.If you are not passing any parameters please remove the parameters I have mentioned and add only this

PropertyInfo pi = new PropertyInfo();
    pi.setType(String.class);
    request.addProperty(pi);

else

 public String Call(String username, String password) {
    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
            OPERATION_NAME);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("username");
    pi.setValue(username);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("password");
    pi.setValue(password);
    pi.setType(String.class);
    request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
    Object response = null;

    try {

        httpTransport.call(SOAP_ACTION, envelope);
        response = envelope.getResponse();
    }

    catch (Exception exception) {
        response = exception.toString();
    }

    return response.toString();
}
Amalan Dhananjayan
  • 2,277
  • 1
  • 34
  • 47
  • My webservice doesn't require parametres ( at least for the HelloWrold Method) but it requires authentication before accessing it – Labraiki Feb 18 '13 at 12:11