【问题标题】:How can I send this SOAP request using KSOAP2 in Android如何在 Android 中使用 KSOAP2 发送此 SOAP 请求
【发布时间】:2013-05-07 20:15:46
【问题描述】:

我对 SOAP 和 Android 非常陌生。有人可以帮我建立一个 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>action@vvz.com</ns:address>
</ns:email>
<ns:password>actionbar123</ns:password>
</ns:identification></ns:identityPoint_identify_request>
</soapenv:Body>
</soapenv:Envelope>

谢谢你

【问题讨论】:

    标签: android soap ksoap


    【解决方案1】:

    我建议您使用 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());
    }
    

    玩得开心!

    【讨论】:

    • 我收到 SoapFault - faultcode: 'SOAP-ENV:Server' faultstring: 'A CXmlApiException was raise error ..#Daniel
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 2011-09-25
    • 2013-08-13
    相关资源
    最近更新 更多