我是Android
,KSOAP
的新手。我主要做.NET
。我正在撰写Android App
,试图从.NET Service
上的IIS Server
提取数据。
导致错误的行是:
androidHttpTransport.call(SOAP_ACTION, envelope);
它失败,但例外:
org.xmlpull.v1.XmlPullParserException:expected:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}信封 (位置:在java.io.InputStreamReader@41527620中START_TAG @ 2:7)
从浏览器调用时,Web Service
我正在调用似乎返回XML
。
我是否需要在IIS Server
上执行某项操作才能从KSOAP2
成功调用服务?
非常感谢任何帮助。
Andriod代码:
package com.example.vdu;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.TextView;
public class DirectorySyncActivity extends Activity {
private static final String NAMESPACE = "http://www.mycompany.com/";
private static final String URL = "http://www.mycompany.com/vdus/service1.asmx/Directory";
private static final String METHOD_NAME = "Directory";
private static final String SOAP_ACTION = "http://www.mycompany.com/vdus/Directory";
Object response;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getdirdata();
}
private void getdirdata() {
new Thread() {
@Override
public void run() {
try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
java.lang.String directorystring = (String)envelope.getResponse().toString();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.directory_sync, menu);
return true;
}
}
答案 0 :(得分:0)
试试这个:
private static final String URL = "http://www.mycompany.com/vdus/service1.asmx";
而不是:
private static final String URL = "http://www.mycompany.com/vdus/service1.asmx/Directory";