Android ksoap2 发送空信封?

发布于 2024-11-30 04:20:37 字数 789 浏览 4 评论 0原文

我想寄一个空信封,如下所示:

     <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:d="http://www.w3.org/2001/XMLSchema" 
     xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
     <v:Header />
        <v:Body>
        </v:Body>
     </v:Envelope>

可以吗?如何发送?我尝试过这个:

     HttpsTransportSE transport = new HttpsTransportSE(HOST, PORT, ENDPOINT, TIMEOUT);
     SoapObject request = new SoapObject(null, null);
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);    
     envelope.setOutputSoapObject(request);
     transport.call(SOAP_ACTION, envelope);

我似乎不知道该怎么做,有人可以帮忙吗?

I want to send an envelope with an empty body like this:

     <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:d="http://www.w3.org/2001/XMLSchema" 
     xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
     <v:Header />
        <v:Body>
        </v:Body>
     </v:Envelope>

Is it possible and how? I've tried with this:

     HttpsTransportSE transport = new HttpsTransportSE(HOST, PORT, ENDPOINT, TIMEOUT);
     SoapObject request = new SoapObject(null, null);
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);    
     envelope.setOutputSoapObject(request);
     transport.call(SOAP_ACTION, envelope);

I can't seem to figure out how to do it, can anyone please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女净妖师 2024-12-07 04:20:37

我通过创建自己的 SoapSerializationEnvelope 来扩展原始的 SoapSerializationEnvelope 并用以下方法重写 writeBody 方法,从而解决了该问题:
public class MySoapEnvelope extends SoapSerializationEnvelope

{   
    public MySoapEnvelope(int version) {
        super(version);
    }
    @Override
    public void writeBody(XmlSerializer writer) throws IOException
    {
        if (bodyOut!=null){
        super.writeBody(writer);
        }   
    }
}

要使用它,您只需使用 MySoapSerializationEnvelope 并设置 Envelope.bodyOut=null;

HttpsTransportSE transport = new HttpsTransportSE(host, port, endpoint, timeout);
MySoapEnvelope emptySoapEnvelope = new MySoapEnvelope(SoapEnvelope.VER11);
emptySoapEnvelope.bodyOut = null;
transport.call(methodname, emptySoapEnvelope);

我不知道你是否想用这段代码剪切一个新版本。我可能会在原始 SoapEnvelope 中创建一个名为 setEmptyEnvelope() 的新方法。但这取决于你。
你可以接受这个,但是你应该做一个受人尊敬的人
文档,以便人们知道这是如何完成的。

I have fixed the problem by creating my own SoapSerializationEnvelope extending the original one and overridering the writeBody method with this:
public class MySoapEnvelope extends SoapSerializationEnvelope

{   
    public MySoapEnvelope(int version) {
        super(version);
    }
    @Override
    public void writeBody(XmlSerializer writer) throws IOException
    {
        if (bodyOut!=null){
        super.writeBody(writer);
        }   
    }
}

To use it, you just have to use the MySoapSerializationEnvelope and set envelope.bodyOut=null;

HttpsTransportSE transport = new HttpsTransportSE(host, port, endpoint, timeout);
MySoapEnvelope emptySoapEnvelope = new MySoapEnvelope(SoapEnvelope.VER11);
emptySoapEnvelope.bodyOut = null;
transport.call(methodname, emptySoapEnvelope);

I dont know if you want to cut a new release with this code. I would possibly make a new method in the original SoapEnvelope called setEmptyEnvelope(). But that's up to you.
You could get along with this, but then you should make a respectable
documentation so people would know this is how it's done.

み青杉依旧 2024-12-07 04:20:37

有趣的。您可能想要调试框架以查看发生了什么。如果您可以为其创建修复程序,我很乐意将其拉入上游并发布新版本。

Interesting. You might want to debug into the framework to see what is going on. If you can create a fix for it I am happy to pull it into upstream and cut a new release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文