如何发出SOAP请求

里沙卜·斯里瓦斯塔瓦(Rishabh Srivastava)

我在Android中提出SOAP请求。我确切想要实现的是:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
   <soap:Header/>
   <soap:Body>
      <tem:GeneratePin>

         <tem:sEmail>[email protected]</tem:sEmail>

         <tem:sFlage>true</tem:sFlage>
      </tem:GeneratePin>
   </soap:Body>
</soap:Envelope>

但我得到:

<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>
<tem:GeneratePin xmlns="http://www.tempuri.org/">
<tem:sEmail>[email protected]</tem:sEmail>
<tem:sFlage>true</tem:sFlage>
</tem:GeneratePin>
</v:Body>
</v:Envelope>

我正在使用以下代码:

static String SOAP_ACTION = "http://tempuri.org/GeneratePin";
    static String namespace = "http://www.tempuri.org/";
    private static String url = "xyz";

    static SoapObject request = null;
    static SoapSerializationEnvelope envelope;
    static HttpTransportSE androidHttpTransport;

    // MethodName variable is define for which webservice function will call
    public static String getPin(String MethodName) {

        try {
            request = new SoapObject(namespace, "tem:GeneratePin");

            /*
             * PropertyInfo pi = new PropertyInfo(); pi.setName("sEmail");
             * pi.setValue("[email protected]"); request.addProperty(pi);
             * 
             * PropertyInfo pi1 = new PropertyInfo(); pi1.setName("sFlage");
             * pi1.setValue("true"); request.addProperty(pi1);
             */

            request.addProperty("tem:sEmail", "[email protected]");
            request.addProperty("tem:sFlage", "true");

            System.out.println("request is : == " + request);
            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
            envelope.dotNet = true;
            envelope.implicitTypes = true;
            envelope.setAddAdornments(false);
            envelope.encodingStyle = "utf-8";
            envelope.setOutputSoapObject(request);
            /*
             * MarshalDouble marshaldDouble = new MarshalDouble();
             * marshaldDouble.register(envelope);
             */

            androidHttpTransport = new HttpTransportSE(url);
            androidHttpTransport.debug = true;

            androidHttpTransport.call(SOAP_ACTION, envelope);
            System.out
                    .println("[email protected]#$%^& " + androidHttpTransport.requestDump);
            /*
             * androidHttpTransport
             * .setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
             */
            final SoapPrimitive response = (SoapPrimitive) envelope
                    .getResponse();
            Log.i("Webservice Output", response.toString());
            return response.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
用户3452758

看起来KSoap在以下名称空间中具有硬编码值SoapEnvelope

https://github.com/karlmdavis/ksoap2-android/blob/master/ksoap2-base/src/main/java/org/ksoap2/SoapEnvelope.java#L182

/**
* Writes the complete envelope including header and body elements to the
* given XML writer.
*/
    public void write(XmlSerializer writer) throws IOException {
        writer.setPrefix("i", xsi);
        writer.setPrefix("d", xsd);
        writer.setPrefix("c", enc);
        writer.setPrefix("v", env);
        writer.startTag(env, "Envelope");
        writer.startTag(env, "Header");
        writeHeader(writer);
        writer.endTag(env, "Header");
        writer.startTag(env, "Body");
        writeBody(writer);
        writer.endTag(env, "Body");
        writer.endTag(env, "Envelope");
    }

SoapSerializationEnvelope你这里创造:

envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 

…是的子类SoapEnvelope因此,要更改行为,您需要SoapSerializationEnvelope像这样类化:

public class CustomSoapSerializationEnvelope extends SoapSerializationEnvelope {

    @Override
    public void write(XmlSerializer writer) throws IOException {
        writer.setPrefix("i", xsi);
        writer.setPrefix("d", xsd);
        writer.setPrefix("c", enc);
        writer.setPrefix("soap", env); // <-- changed line
        writer.startTag(env, "Envelope");
        writer.startTag(env, "Header");
        writeHeader(writer);
        writer.endTag(env, "Header");
        writer.startTag(env, "Body");
        writeBody(writer);
        writer.endTag(env, "Body");
        writer.endTag(env, "Envelope");
    }
}

然后,将上面的行替换为:

envelope = new CustomSoapSerializationEnvelope(SoapEnvelope.VER12); 

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从SQL Server发出HTTP请求?

来自分类Dev

如何使用AFNetworking或STHTTPRequest发出SOAP Web服务请求?

来自分类Dev

如何使用Express框架发出AJAX请求?

来自分类Dev

如何通过使用SOAPpy发出SOAP请求?

来自分类Dev

如何发出jsonp请求

来自分类Dev

如何使用grequests发出HTTP POST请求

来自分类Dev

如何在PHP中发出HTTP请求?

来自分类Dev

AFNetworking 2.0,SOAP Web服务:如何发出请求?

来自分类Dev

如何创建SOAP 1.2请求

来自分类Dev

如何从COBOL发出HTTP请求

来自分类Dev

如何使用TortoiseGit发出请求请求

来自分类Dev

如何通过Cookie发出HTTP请求

来自分类Dev

如何创建发出ajax请求的angularjs指令?

来自分类Dev

如何发出多个http呼叫请求(Nodejs)

来自分类Dev

如何间隔发出HTTP请求?

来自分类Dev

如何使用TcpClient向网站发出请求

来自分类Dev

如何在jQuery中发出放置请求

来自分类Dev

RxJs:如何发出同步请求?

来自分类Dev

如何使用EGit发出拉动请求?

来自分类Dev

如何使用SwiftyJSON发出发布请求

来自分类Dev

如何向OpsGenie发出POST请求?

来自分类Dev

如何使用FRENDS发出SOAP请求?

来自分类Dev

如何从URL池发出并发GET请求

来自分类Dev

如何从getStaticProps向API路由发出请求

来自分类Dev

如何查看网络上发出的http请求?

来自分类Dev

如何对wcf服务使用usd Zend \ Soap \ Client \ DotNet发出肥皂请求?

来自分类Dev

如何使用AFNetworking或STHTTPRequest发出SOAP Web服务请求?

来自分类Dev

如何拦截从Salesforce发出或在Salesforce中收到的SOAP请求/响应?

来自分类Dev

如何发出发帖请求

Related 相关文章

热门标签

归档