2

可能重复:
Android,通过 HTTP POST (SOAP) 发送 XML

如何在 android 中发布对 SOAP 服务的请求?

请给我一些例子

谢谢你给我分享知识

4

1 回答 1

0

使用KSoap 库,这是我项目中的代码片段:

SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
                METHOD_NAME_NIST_IMPORT);

        ImportNistFileReq nistReq = new ImportNistFileReq(nistFile);

        PropertyInfo pi = new PropertyInfo();
        pi.setName("req");
        pi.setValue(nistReq);
        pi.setType(nistReq.getClass());
        soapObject.addProperty(pi);


        SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        new MarshalBase64().register(soapSerializationEnvelope);

        soapSerializationEnvelope.setOutputSoapObject(soapObject);

        soapSerializationEnvelope.addMapping(NAMESPACE_NIST_IMPORT, "ImportNistFileReq", new ImportNistFileReq().getClass());


        soapSerializationEnvelope.dotNet = true;
        Object objectResult = null;

        try {
            HttpTransportSE httpTransportSE = new HttpTransportSE(
                    URL_NIST_IMPORT);

            httpTransportSE.debug = true;
            httpTransportSE.call(SOAP_ACTION_NIST_IMPORT, soapSerializationEnvelope);

            String host = httpTransportSE.getPath();
            Log.i("HOST: ", host);

            objectResult = (Object) soapSerializationEnvelope.getResponse();


        } catch (IOException e) {
            Log.e("IO: ", e.getMessage());
        } catch (XmlPullParserException e) {
            Log.e("XML: ", e.getMessage());
        }

这段代码发送一个NIST 文件,表示为 Web 服务的byte array编码Byte64。像这样的请求应该在一个单独的线程中调用,比如AsyncTask ..

常数:

  • NAMEPSPACE_NIST_IMPORT
  • 方法名_NIST_IMPORT
  • URL_NIST_IMPORT
  • SOAP_ACTION_NIST_IMPORT

指的是我的.NET服务提供的wsdl文件。这是一个很棒的教程。如果有什么不清楚的,就问吧。祝你好运。

于 2012-10-17T09:42:32.913 回答