尝试使用此类调用 Web 服务:
public class WSRequest {
public HttpTransportSE androidHttpTransport;
public SoapSerializationEnvelope envelope;
public String methodName;
public SoapObject request;
public WSRequest(String methodName)
{
this.methodName = methodName;
this.request = new SoapObject(SRWebServer.NAMESPACE, methodName);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(SRWebServer.URL);
}
public void RegisterMarshal()
{
MarshalBase64 marshal = new MarshalBase64();
marshal.register(envelope);
}
public SoapObject Send() throws IOException, XmlPullParserException
{
System.setProperty("http.keepAlive", "false");
new MarshalDate().register(envelope);
this.androidHttpTransport.call(SRWebServer.NAMESPACE + this.methodName, envelope);
return (SoapObject) this.envelope.getResponse();
}
public void AddProperties(String name, Object value)
{
this.request.addProperty(name, value);
}
//
}
并使用这种方式:
WSRequest request = new WSRequest("method name here");
request.addProperties("property1Name",property1);
request.Send();
requestSend()
将返回一个包含从 Web 服务接收到的对象的 SoapObject。