我在android中为DBConnection起诉asp.net webservice(visual studio 2008)。
它运行成功。
我的Android代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final AlertDialog ad=new AlertDialog.Builder(this).create();
TextView tv=(TextView)findViewById(R.id.tvArray);
Button btnCall=(Button)findViewById(R.id.btnCall);
btnCall.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
CallSoap cs=new CallSoap();
try
{
String name=cs.Call();
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_LONG).show();
}
catch(Exception ex)
{
ad.setMessage(ex.getMessage());
}
}
});
}
和callsoap方法:
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.Toast;
public class CallSoap
{
public final String SOAP_ACTION ="http://tempuri.org/GetData";
public final String OPERATION_NAME = "GetData";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://10.0.2.2:8080/Service1.asmx";
public CallSoap()
{
}
public String Call()
{
SoapObject req=new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
//envelope.headerOut = security; // this is an Element[] created before
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
envelope.setOutputSoapObject(req);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response=null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
//Toast.makeText(this, "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
}
catch (Exception exception)
{
response=exception.toString();
}
return response.toString();
}
}
当我点击应用程序上的按钮时,它给出了错误:
android org.xmlpull.v1.xmlpullparserexception期望start_tag http //schemas.xmlsoap.org/soap/envelope/信封位置开始标记
我在堆栈上有很多关于此的问题。
我发现它通常是由于写错了服务方法而发生的。
但在我的情况下,我检查了所有这些。一切都是对的。
你也可以检查一下:我抓住了我正在运行的服务器,其中给出了每一件事:
请帮帮我。
答案 0 :(得分:1)
我认为您必须输入端口号而不是8080