【问题标题】:How to connect localhost SOAP webservice to my android如何将 localhost SOAP webservice 连接到我的 android
【发布时间】:2013-10-01 22:20:51
【问题描述】:

我正在研究webservice 我对网络服务没有任何想法。我看起来相同的示例 web 服务(如实时 SOAP 服务)它工作正常。我要在 localhost i dont know whether my URL,Namespace and methodName are declared correctly 中运行 web 服务。

以下代码是我的WSDL代码

<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"   
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:xs0="http://www.processmaker.com"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"   
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns="http://schemas.xmlsoap.org/wsdl/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
targetNamespace="http://www.processmaker.com">
<types>
<xs:schema elementFormDefault="qualified"     
targetNamespace="http://www.processmaker.com">
<xs:element name="login">
<xs:complexType>
<xs:sequence>
<xs:element name="userid" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</definitions>

我调用上述服务的android代码:

public class MainActivity extends Activity {
String str = null;
private static final String SOAP_ACTION = "http://www.processmaker.com/Login";
private static final String METHOD_NAME = "Login";
private static final String NAMESPACE = "http://www.processmaker.com/";
private static final String URL = "http://192.168.1.5/sysworkflow/en/neoclassic/setup/main";
SoapObject request;
TextView tv;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.activity_main);

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


    DownloadWebPageTask task = new DownloadWebPageTask();
    task.execute();
}


private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
      String response = "";

        try {
            request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo weightProp = new PropertyInfo();
            weightProp.setName("USER_ID");
            weightProp.setValue("admin");
            weightProp.setType(String.class);
            request.addProperty(weightProp);

            PropertyInfo fromProp = new PropertyInfo();
            fromProp.setName("PASSWORD");
            fromProp.setValue("admin");
            fromProp.setType(String.class);
            request.addProperty(fromProp);

            /*
             * PropertyInfo toProp =new PropertyInfo(); toProp.setName("ToUnit");
             * toProp.setValue(toUnit); toProp.setType(String.class);
             * request.addProperty(toProp);
             */
            final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            final HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapPrimitive response1 = (SoapPrimitive) envelope.getResponse();
                Log.i("myApp", response1.toString());
            //  tv.setText(response.toString());
                Toast.makeText(getApplicationContext(), response.toString(),
                        Toast.LENGTH_LONG).show();

            } catch (Exception e) {
                tv.setText(e.toString());

                e.printStackTrace();

            }
          }

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

    @Override
    protected void onPostExecute(String result) {
      tv.setText(result);
    }
  }

请有人帮我做这件事..

【问题讨论】:

标签: android web-services soap wsdl


【解决方案1】:

你好,像这样使用。

 private static final String SOAP_ACTION = "http://www.processmaker.com/Login";
private static final String METHOD_NAME = "Login";
private static final String NAMESPACE = "http://www.processmaker.com";
private static final String URL = "http://10.0.2.2/sysworkflow/en/classic/services/wsdl2";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userid", "admin");
request.addProperty("password", "admin");

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

  HttpTransportSE ht = new HttpTransportSE(URL);

 try {
    ht.call(SOAP_ACTION, envelope);
    final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
    str = response.toString();

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

  }
    Log.d("WebRespone", str);

希望这会对你有所帮助。

【讨论】:

  • +1) 感谢您的回复,它显示连接超时异常。
  • @Ela 检查我编辑的答案。如果你没有得到输出,问题可能是你的 URL。
  • @Ela 你的错误是什么。如果您遇到严格模式错误,请使用异步任务。
  • 我解决了强制关闭错误但发生连接超时异常请帮我解决这个问题...
  • 它只到这一行... ht.call(SOAP_ACTION, envelope);然后去抓块...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-20
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多