2013-05-07 127 views
0

我對SOAP和Android非常陌生。有人可以幫助我構建一個SOAP請求來發送以下請求。如何在Android中使用KSOAP2發送此SOAP請求

SOAPAction: http://api.example.com/application 

Request 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns="http://api.example.com/registration/v3.1"> 
<soapenv:Header> 
<ns0:appCredentials ns0:name="your-account-name" ns0:password="mypassword" ns0:targetAccountName="vvz" 
xmlns:ns0="http://services.example.com/application/types/1.0"/> 
</soapenv:Header> 
<soapenv:Body> 
<ns:identityPoint_identify_request> 
<ns:identification type="email-password"> 
<ns:email> 
<ns:address>[email protected]</ns:address> 
</ns:email> 
<ns:password>actionbar123</ns:password> 
</ns:identification></ns:identityPoint_identify_request> 
</soapenv:Body> 
</soapenv:Envelope> 

感謝您

回答

0

我建議你使用KSOAP2 java庫。它非常簡單和偉大的自由。 即時使用它很長一段時間。 你可以在簡單的java代碼中構建你想要的任何soap對象。

這裏:http://simpligility.github.io/ksoap2-android/index.html

一個簡單的例子:

private static final String SOAP_ACTION = "http://tempuri.org/GetInteger2"; 
private static final String METHOD_NAME = "GetInteger2"; 
private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL = "http://10.0.22:4711/Service1.asmx"; 

public int GetInteger2() throws IOException, XmlPullParserException { 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    PropertyInfo pi = new PropertyInfo(); 
    pi.setName("i"); 
    pi.setValue(123); 
    request.addProperty(pi); 

    SoapSerializationEnvelope envelope = 
     new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 

    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); 
    androidHttpTransport.call(SOAP_ACTION, envelope); 

    SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); 
    return Integer.parseInt(result.toString()); 
} 

有樂趣!

+0

我得到SoapFault - faultcode:'SOAP-ENV:Server'faultstring:'一個CXmlApiException被引發錯誤..#Daniel – 2015-03-25 10:46:02