任何人都可以帮助处理来自Android应用程序的SOAP请求和响应。
我已经按照教程了 http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/
但是当我运行应用程序时,它会因错误而过早退出
不幸的是,已经停止了。
我在模拟器中运行它。
任何人都可以解释一下我可能会遗漏的内容。任何示例源代码都非常有用。
答案 0 :(得分:0)
我有一个简单的代码。我们有一个按钮,我们将调用helloworld方法。
Button Worldmethod;
private static final String SOAP_ACTION1 = "http://tempuri.org/HelloWorld";
private static final String HelloWorldmethod = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.5/MobileDemo/Demo.asmx";
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.webservices_layout);
Worldmethod= (Button)findViewById(R.id.Worldmethod);
Worldmethod.setOnClickListener(this);
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.Worldmethod:
try
{
methodbody= (TextView)findViewById(R.id.methodbody);
SoapObject request1 = new SoapObject(NAMESPACE, HelloWorldmethod);
// add paramaters and values
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request1);
//Web method call
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION1, envelope);
//get the response
SoapPrimitive result= (SoapPrimitive)envelope.getResponse();
String results = result.toString();
methodbody.setText( ""+results);
}
catch (Exception e)
{
methodbody.setText(e.getMessage());
e.printStackTrace();
}
break;
}
}