创建使用KSOAP Android的SOAP请求 [英] Create SOAP request using KSOAP Android

查看:256
本文介绍了创建使用KSOAP Android的SOAP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成这样一个SOAP请求。

I need to generate a soap request like this one.

SOAP-REQUEST

POST /TennisMasters/TennisMasters.Listener.asmx HTTP/1.1
Host: playinkstudio.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://playinktennismasters.com/authenticateUser"

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <authenticateUser xmlns="http://playinktennismasters.com/">
          <user>string</user>
        </authenticateUser>
      </soap:Body>
    </soap:Envelope>

我使用KSOAP2,打造了这一请求。

I am using KSOAP2, to build this request.

private static String SOAP_ACTION = "http://playinktennismasters.com/authenticateUser";
private static String NAMESPACE = "http://playinktennismasters.com/";
private static String METHOD_NAME = "authenticateUser";
private static String URL = "http://playinkstudio.com/TennisMasters/TennisMasters.Listener.asmx";

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("user", "A Json String will be here");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER12);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
    } catch (Exception e) {
        e.printStackTrace();
    }

这是我从调试得到了请求。

This is the request which I got from debugging.

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header />
<v:Body>
<authenticateUser xmlns="http://playinktennismasters.com/" **id="o0" c:root="1"**>
<user **i:type="d:string"**>{"email":"asad.mahmood@gmail.com","UserDate":"Feb 22, 2012 7:01:24 PM","GearId":0,"GearValue":0,"Income":0,"Level":0,"MatchResult":0,"MatchType":0,"OfferId":0,"OpponentId":0,"Partners":0,"ExhibitionCount":0,"PowerRuns":0,"PowerServes":0,"PowerShots":0,"Seeds":0,"Energy":0,"Cash":0,"Stamina":0,"Strength":0,"SubLevel":0,"TotalEnergy":0,"TotalStamina":0,"TrainingId":0,"Agility":0,"UserId":0,"Age":0,"ActivityId":0,"gearIsGift":0}</user>
</authenticateUser>
</v:Body>
</v:Envelope>

我不知道为什么像ID和附加属性C:根在的authenticateUser添加。
在我额外的属性:TYPE =D:字符串。
请能来有人给我一个很好的例子或教程可以指导我创造像上面的要求,真正需要帮助的感谢。

I don't know why extra attributes like "id" and "c:root" are being added in authenticateUser. and extra attribute in i:type="d:String". Please can come someone give me a good example or tutorial which can guide me to create a request like above,Really Need help thanks.

推荐答案

终于得到了它的工作KSOAP。这里是code我以前也许这将帮助别人。

Finally got it working with KSOAP. Here is the code I used maybe it will help someone.

final SoapObject request = new SoapObject(AppConsts.NAMESPACE,
                usecaseString);
        request.addProperty(addPropertyString, propertyJsonString);
        final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        final HttpTransportSE androidHttpTransport = new HttpTransportSE(
                AppConsts.URL);
        androidHttpTransport.debug = true;
        String soapAction = AppConsts.NAMESPACE + usecaseString;

        try {
            androidHttpTransport.call(soapAction, envelope);
            SoapPrimitive resultSoapPrimitive;
            resultSoapPrimitive = (SoapPrimitive) envelope.getResponse();
            if (resultSoapPrimitive != null) {
                result = resultSoapPrimitive.toString();
                if (AppConsts.ENABLE_LOG)
                    Log.d(AppConsts.GAME_TITLE, "result json : " + result);
            } else {
                if (AppConsts.ENABLE_LOG)
                    Log.d(AppConsts.GAME_TITLE, "result json is NULL!!! ");

            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("static", "Exception in making call to server");
        }

有关创建上述要求这三个参数,我们需要传递到code。

For creating above request these three parameter we need to pass into code.

 AppConsts.NAMESPACE =  "http://playinktennismasters.com"
usecaseString = "authenticateUser"
addPropertyString = "user"

这篇关于创建使用KSOAP Android的SOAP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆