构建KSoap2请求

时间:2015-03-05 04:15:18

标签: android ksoap2 android-ksoap2

我有如下的请求,并使用SoapUI进行测试。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dien="http://www.myserver.com/ws/dientityx" xmlns:de="http://www.myserver.com/ws/de">
   <soapenv:Header/>
   <soapenv:Body>
      <dien:EnrollUser>
         <de:GenericParams>
            <de:AppID>km</de:AppID>
            <de:AppUD>km</de:AppUD>
         </de:GenericParams>
         <dien:Version>V3_2_1</dien:Version>
         <dien:ProfileID>profile1</dien:ProfileID>
         <dien:DeviceInfo>
            <dien:Devicedientifier>profile1</dien:Devicedientifier>
         </dien:DeviceInfo>         
         <dien:finger>
            <!--Optional:-->
            <dien:Data>
          Userdatahere
</dien:Data>
            <!--Optional:-->
            <dien:ImageType>JPG</dien:ImageType>
         </dien:finger>
      </dien:EnrollUser>
   </soapenv:Body>
</soapenv:Envelope>

我使用KSoap2

编写了以下Android代码
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            envelope.implicitTypes = true;
            envelope.setAddAdornments(false);

            SoapObject request = new SoapObject(NAMESPACE, METHOD);

            PropertyInfo pi = new PropertyInfo();
            pi.setNamespace(NAMESPACE);
            pi.setName("AppID");
            pi.setValue("km");
            request.addProperty(pi);

            request.addProperty("AppUD","km");
            request.addProperty("Version","V3_2_1");
            request.addProperty("ProfileID","profile1");
            request.addProperty("DeviceIdentifier","12345");
            request.addProperty("finger",finger);
            //bodyOut is the body object to be sent out with this envelope
            envelope.bodyOut = request;
            allowAllSSL(MainActivity.this);
            HttpTransportSE transport = new HttpTransportSE(URL);
            transport.debug = true;
            try {
                //transport.call(NAMESPACE + METHOD, envelope);
                transport.call(NAMESPACE + METHOD, envelope);
                Log.e(TAG,"dumping request "+transport.requestDump);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
            //bodyIn is the body object received with this envelope
            if (envelope.bodyIn != null) {
                /*SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn)
                        .getProperty(0);*/

                SoapObject response = (SoapObject)envelope.bodyIn;

                String resp=response.getPropertyAsString(0).toString();
                Log.e(TAG,"resp = "+resp);

            }

请求似乎没有正确发送。如何添加更改信封,添加参数APPID和APPUD,手指?

0 个答案:

没有答案