我一直在尝试使用 .NET webservice(首先测试的 HelloWorld 方法),使用几乎与另一个 webservice 相同的代码。
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://demo.digiparc.com/autocomplete.asmx";
private static final String TAG = "MyActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView)findViewById(R.id.textView1);
SoapObject Request = new SoapObject(NAMESPACE,METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(Request);
HttpTransportSE aht = new HttpTransportSE(URL);
try{
aht.call(SOAP_ACTION,envelope);
Log.i(TAG, "ind");
SoapPrimitive resultString = (SoapPrimitive)envelope.getResponse();
System.out.println("Result: "+resultString);
tv.setText("Status : " + resultString);
}
catch(Exception e){
Log.i(TAG, e.toString());
e.printStackTrace();
}
}
我的第一个日志没有出现在 logcat 中,第二个日志我发现了以下异常:
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@1:6 in java.io.InputStreamReader@45f9a950)
难道我做错了什么 ?如果有人遇到同样的问题或有任何线索可以提供帮助吗?我的 Web 服务详细信息是准确的。