我正在使用KSOAP2库来调用ASP.NET Web服务。我没有收到任何错误,但我也没有得到任何回应任何想法来解决这个问题。
以下是我的代码。我只是调用helloworld默认方法返回一个字符串。
public class MainActivity extends Activity {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://(ip)/TrialService.asmx";
private final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private final String METHOD_NAME = "HelloWorld";
TextView t1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = (TextView) findViewById(R.id.textView1);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
String receivedInt = (String) envelope.getResponse();
t1.setText(receivedInt);
setContentView(t1);
} catch (Exception e) {
t1.setText("error");
}
}
}
答案 0 :(得分:0)
首先启动调试,以便您可以看到要发送到服务器的soap信封的内容,您可以通过添加来执行此操作(请参阅注释部分):
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;//ADD THIS
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
//ADD THESE 2
//Important Outputs to check how the request/Response looks like.. Check them in Logcat to find these outputs
System.out.println("requestDump is :"+androidHttpTransport.requestDump);//ADDED
System.out.println("responseDump is :"+androidHttpTransport.responseDump);//ADDED
String receivedInt = (String) envelope.getResponse();
t1.setText(receivedInt);
setContentView(t1);
} catch (Exception e) {
t1.setText("error");
}
现在您可以看到发送到您服务器的soap信封,检查它是否准确。 (您可以使用SoapUI.)
等程序将其与桌面发送的信封进行比较 下一步:
您必须提供更多详细信息,以便我们更好地为您提供帮助:提供相关WSDL部件的副本。
确保您使用的准确值为:NAMESPACE,METHOD_NAME,网址,SOAP_ACTION
如果这是一个测试项目并且您可以访问服务器,您可以将其作为奖励来检查服务器上发生的情况你发送请求。