Soap api calling with ksoap

让人想犯罪 __ 提交于 2019-12-12 02:25:26

问题


how to get proper response in android app. My api original response is display in soapUi software

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
  <GetSourcesResponse xmlns="...">
     <GetSourcesResult>
        <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
           <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="ITS" msdata:UseCurrentLocale="true">
              <xs:complexType>
                 <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="ITS">
                       <xs:complexType>
                          <xs:sequence>
                             <xs:element name="CM_CityID" type="xs:int" minOccurs="0"/>
                             <xs:element name="CM_CityName" type="xs:string" minOccurs="0"/>
                          </xs:sequence>
                       </xs:complexType>
                    </xs:element>
                 </xs:choice>
              </xs:complexType>
           </xs:element>
        </xs:schema>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
           <DocumentElement xmlns="">
              <ITS diffgr:id="ITS1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
                 <CM_CityID>645</CM_CityID>
                 <CM_CityName>Ahmednagar</CM_CityName>
              </ITS>
              <ITS diffgr:id="ITS2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
                 <CM_CityID>2762</CM_CityID>
                 <CM_CityName>Airoli</CM_CityName>
              </ITS>
           </DocumentElement>
        </diffgr:diffgram>
     </GetSourcesResult>
  </GetSourcesResponse>

and i call this api to get response like

getResponse
{
  getResponseResult=anyType
  {
    schema=anyType
    {
      element=anyType
      {
        complexType=anyType
        {
          choice=anyType
          {
            element=anyType
            {
              complexType=anyType
              {
                sequence=anyType
                {
                  element=anyType{};
                  element=anyType{};
                };
              }; 
            };
          };
        };
      };
    };
    diffgram=anyType{};
  };
}

how to get proper original response plz help me.....thanks in advance


回答1:


Use Wsdl2Code tool

It's a web tool that helps developers consume .net web services.

  1. Open above schemas in browser save as .wsdl extension
  2. Upload file.wsdl into Wsdl2Code
  3. Download Auto generated code
  4. Paste in your package
  5. Use Service class for Read, Write and Update from server

sample code from Service class

public VectorClass ReadMultiple(VectorClass filter,
        String bookmarkKey, int setSize, List<HeaderProperty> headers) {
    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    soapEnvelope.implicitTypes = true;
    soapEnvelope.dotNet = true;
    SoapObject soapReq = new SoapObject(
            "urn:microsoft-dynamics-schemas/page/classsName",
            "ReadMultiple");
    for (int i = 0; i < filter.size(); i++) {
        soapReq.addProperty("filter", getSOAPVector(filter, i));
    }
    // soapReq.addProperty("filter", filter);
    soapReq.addProperty("bookmarkKey", bookmarkKey);
    soapReq.addProperty("setSize", setSize);
    soapEnvelope.setOutputSoapObject(soapReq);
    NtlmTransport ntml = new NtlmTransport(url,
            SharedPreferenceUtil.getString("userName", "username"),
            SharedPreferenceUtil.getString("passWord", "password"),
            SharedPreferenceUtil.getString("domainName", "domainname"),
            SystemService.domainName);
    try {
        if (headers != null) {
            ntml.call(
                    "urn:microsoft-dynamics-schemas/page/className/ReadMultiple",
                    soapEnvelope, headers);
        } else {
            ntml.call(
                    "urn:microsoft-dynamics-schemas/page/className/ReadMultiple",
                    soapEnvelope);
        }
        Object retObj = soapEnvelope.bodyIn;
        if (retObj instanceof SoapFault) {
            SoapFault fault = (SoapFault) retObj;
            Log.e("Fault", "" + fault);
            Exception ex = new Exception(fault.faultstring);
            if (eventHandler != null)
                eventHandler.Wsdl2CodeFinishedWithException(ex);
        } else {
            SoapObject result = (SoapObject) retObj; //Soap success response
            if (result.getPropertyCount() > 0) {
                Object obj = result.getProperty(0);
                SoapObject j = (SoapObject) obj;
                Log.e("Navpos Header Response", ""+result);
                VectorClassName resultVariable = new VectorClassName(
                        j);

                return resultVariable;
            }
        }
    } catch (Exception e) {
        if (eventHandler != null)
            eventHandler.Wsdl2CodeFinishedWithException(e);
        e.printStackTrace();
    }
    return null;
}


来源:https://stackoverflow.com/questions/42359160/soap-api-calling-with-ksoap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!