开发者

Trying to get any response when connecting from Android to my web service (SOAP 1.1)

This is my only class where i get connected to my web service :

    public class Main extends Activity {
    /** Called when the activity is first created. */

 private static final String SOAP_ACTION="http://tempuri.org/getme/TSM/LogOn";
 private static final String METHOD_NAME="LogOn";
 private static final String NAMESPACE="http://tempuri.org/getme/TSM/";
 private static final String URL="http://theking/eget/WebService/WSAuth.asmx";

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tv = (TextView) findViewById(R.id.TextView01);

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        Request.addProperty("strUsername", "Test");
        Request.addProperty("strPassword", "Test123");
        Request.addProperty("strMessage", "hello");

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

        AndroidHttpTransport aht = new AndroidHttpTransport(URL);
        try
        {
         aht.call(SOAP_ACTION, soapEnvelope);
         SoapObject response = (SoapObject)soapEnvelope.g开发者_如何学编程etResponse();
            String LogonResult =  response.getProperty(0).toString();
            String MessageResult =  response.getProperty(1).toString();
         tv.setText("Status : " + LogonResult + " Message: " + MessageResult);
        }
        catch(Exception e)
        {
         e.printStackTrace();
        }

    } }

I think it breaks before the TRY tag.. all i get on the virtual screen is : false. Any solutions.. i don't know where is the problem ?

The following is a sample SOAP request and response.

<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>
    <LogOn xmlns="http://tempuri.org/getme/TSM">
      <strUsername>string</strUsername>
      <strPassword>string</strPassword>
      <strMessage>string</strMessage>
    </LogOn>
  </soap:Body>
</soap:Envelope>

    <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>
    <LogOnResponse xmlns="http://tempuri.org/getme/TSM">
      <LogOnResult>int</LogOnResult>
      <strMessage>string</strMessage>
    </LogOnResponse>
  </soap:Body>
</soap:Envelope>


I had the same problem I just add this permission in AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

Thats it :)


make sure that in your android application config file you have allowed remote access.

Also try pasting the URL into a browser and see whether it is correct.

Also set a breakpoint or log in a file to determine whether the service will get invoked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜