android中的Web服务

时间:2012-05-02 04:25:50

标签: android soap

我是android新手。在我的应用程序中,我试图调用SOAP Web服务,因为我无法理解是什么意思

有(SOAP_Action,OperationName,WSDL_TARGET_NAMESPACE,SOAP_ADDRESS)。以下是我的完整代码

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

TextView textView = new TextView(this);

setContentView(textView);

SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
System.out.println("subbu="+request);
envelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 
try 
{ 
httpTransport.call(SOAP_ACTION, envelope); 
Object response = envelope.getResponse();
textView.setText(response.toString()); 
} 
catch (Exception exception) 
{ 
textView.setText(exception.toString());
}
}
}

任何人都可以解释这是为了什么目的。给出一些我可以了解的链接。

1 个答案:

答案 0 :(得分:0)

SOAP_ACTION / NAMESPACE和METHODS可以在目标Web服务的WSDL文件中找到!

以下是将SOAP请求发送到Web服务的示例代码:

public class SoapRequest {
private static final String SOAP_ACTION = "xxx";
private static final String METHOD_NAME = "xxx";
private static final String NAMESPACE = "xxx";
private static final String URL = "url of the webservice";

public static SoapObject soap() throws IOException, XmlPullParserException {
    SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);

/* Here you can add properties to your requests */
    PropertyInfo pi1 = new PropertyInfo();
    pi1.name = "xxx";
    pi1.type = String.class;
    request.addProperty(pi1, "xxx");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true; 
    androidHttpTransport.call(SOAP_ACTION, envelope);
    SoapObject soapResult = (SoapObject) envelope.bodyIn;
    return soapResult;
}