0

我是安卓新手。在我的应用程序中,我尝试调用 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());
}
}
}

任何人都可以解释那是什么目的。提供一些链接,我可以从中得到想法。

4

1 回答 1

0

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

下面是向 webservice 发送 SOAP 请求的示例代码:

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;
}
于 2014-07-12T08:21:43.473 回答