如何从Android中的SOAP获得正确的响应?

时间:2014-04-09 22:10:35

标签: android xml soap wsdl response

我是Android初学者,我在这里待了很长时间......

我的问题:这是我得到的回复,而不是预期的xml文件,但是:

## <xs:element name="dsKurs" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
  <xs:complexType>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
       <xs:element name="KursZbir">
        <xs:complexType>
           <xs:sequence>
             <xs:element name="RBr" type="xs:double" minOccurs="0" />
             <xs:element name="Datum" type="xs:dateTime" minOccurs="0" />
             <xs:element name="Valuta" type="xs:double" minOccurs="0" />
             <xs:element name="Oznaka" type="xs:string" minOccurs="0" />
             <xs:element name="Drzava" type="xs:string" minOccurs="0" />
            <xs:element name="Nomin" type="xs:double" minOccurs="0" />
             <xs:element name="Sreden" type="xs:double" minOccurs="0" />
             <xs:element name="DrzavaAng" type="xs:string" minOccurs="0" />
            <xs:element name="NazivMak" type="xs:string" minOccurs="0" />
             <xs:element name="NazivAng" type="xs:string" minOccurs="0" />
             <xs:element name="Datum_f" type="xs:dateTime" minOccurs="0" />
           </xs:sequence>
         </xs:complexType>
      </xs:element>
    </xs:choice>
   </xs:complexType>
 </xs:element>

< / XS:模式>  < / dsKurs>  ##

以下是我的一些代码:

private static String SOAP_ACTION = "http://www.nbrm.mk/klservice/GetExchangeRateD";
private static String NAMESPACE = "http://www.nbrm.mk/klservice/";
private static String METHOD_NAME_SUM = "GetExchangeRateDResponse";
private static String URL = "http://www.nbrm.mk/klservice/kurs.asmx?WSDL";

public class LoadTaskj extends AsyncTask<Void, Void, String> {

    String StartDate, EndDate = "";

    @Override
    protected String doInBackground(Void... params) {

        StartDate = sum1.getText().toString();
        EndDate = sum2.getText().toString();

        // TODO Auto-generated method stub

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_SUM);
        request.addProperty("StartDate", StartDate);
        request.addProperty("EndDate", EndDate);
        // Use this to add parameters

        // Declare the version of the SOAP request
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.setOutputSoapObject(request);

        // Needed to make the internet call
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {

            androidHttpTransport
                    .setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            androidHttpTransport.debug = true;
            androidHttpTransport.call(SOAP_ACTION, envelope);
            // String ss=androidHttpTransport.requestDump;

            // System.out.println(ss);
            // t.setText(ss);

        } catch (Exception e) {
            e.printStackTrace();
        }

        SoapObject result = null;
        if (envelope.bodyIn instanceof SoapFault) {
            String str = ((SoapFault) envelope.bodyIn).faultstring;
            Log.i("WS 1", str);

            // Another way to travers through the SoapFault object
        } else {

            try {
                Object resi = envelope.getResponse();
                SoapPrimitive resultce = (SoapPrimitive) envelope
                        .getResponse();

                if (resultce != null) {
                    // resultce=(SoapObject)envelope.bodyIn;

                    Log.i("loook at mee", String.valueOf(resultce));

                }

            } catch (SoapFault e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // od poc kod
            result = (SoapObject) envelope.bodyIn;
            Log.d("WS", String.valueOf(result));
            // od poc kod

            String requestString = androidHttpTransport.requestDump;
            Log.d("Request in XML", requestString);
            String response1 = androidHttpTransport.responseDump;
            Log.d("Response in XML", response1);

        }

        // Get the SoapResult from the envelope body.

        String resultString = "";
        if (result != null) {
            resultString = result.getProperty(0).toString();

        }
        return resultString;

    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub

        // String callService = callService(firstSum, secondSum);
        // t.setText(result);
        super.onPostExecute(result);
    }

}

以下是POST响应和请求的链接: http://www.nbrm.mk/klservice/kurs.asmx?op=GetExchangeRateD

我错过了什么或做错了什么?请帮我。 有关详细信息,请参阅:http://www.nbrm.mk/klservice/kurs.asmx

1 个答案:

答案 0 :(得分:1)

我确定你可能想要改变你的

private static String METHOD_NAME_SUM = "GetExchangeRateDResponse";

private static String METHOD_NAME_SUM = "GetExchangeRate";

并指定开始日期和结束日期。