使用不带“i:type=”的 addMapping Android 版 ksoap2 中的属性

发布于 2024-10-25 18:05:45 字数 5224 浏览 1 评论 0原文

我在ksoap2中使用envelope.addMapping函数,我需要让它生成没有i:type属性的项目。

这是我的代码生成的肥皂请求

<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>
        <ApiKey xmlns="urn:example:data">APIKey</ApiKey>
    </v:Header>
    <v:Body>
        <CreateScan xmlns="urn:example:services" id="o0" c:root="1">
            <scan i:type="n3:" xmlns:n3="">
                <n4:BaseUrl i:type="d:string" xmlns:n5="urn:example:data">http://www.example.com</n5:BaseUrl>
                <n5:DisplayName i:type="d:string" xmlns:n7="urn:example:data">Example Scan</n7:DisplayName>
            </scan>
        </CreateScan>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

,我需要使它生成 ;

这是我的代码

package ksoap2.test;

import java.util.Hashtable;
import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class ksoap2 extends Activity {
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION = "http://example.com/OperationsService.svc";
    private static final String METHOD_NAME = "CreateScan";
    private static final String NAMESPACE = "urn:example:services";
    private static final String URL = "http://example.com/OperationsService.svc";
    private AndroidHttpTransport androidHttpTransport;
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.textView1);

        try {
            Element ApiKeyElement = new Element().createElement("", "ApiKey");
            ApiKeyElement.setAttribute("", "xmlns", "urn:example:data");
            ApiKeyElement.addChild(Node.TEXT, "22DF0959F20743660304CB829B3891F0");


            Element[] header = new Element[1];
            header[0]=ApiKeyElement;


            Element request = new Element().createElement(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);          
//              PropertyInfo scanProp = new PropertyInfo();
//              scanProp.setName("scan");
//              scanProp.setValue("");

                SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
                Scan s = new Scan();
                s.BaseUrl="http://www.example.com";
                s.DisplayName="Example";

                PropertyInfo pi = new PropertyInfo();
                pi.setName("scan");
                pi.setValue(s);
                pi.setType(s.getClass());
                Request.addProperty(pi);

                //request.addChild(Node.ELEMENT, scanElement);
                envelope.headerOut = header;
                //envelope.dotNet = true;
                envelope.setOutputSoapObject(Request);

                envelope.addMapping(null, "scanItem",new Scan().getClass());
                envelope.dotNet =false;
                String BodyClass = envelope.bodyOut.getClass().toString();
                SoapObject body = (SoapObject)envelope.bodyOut;
                int count =body.getPropertyCount();
                //envelope.encodingStyle = "test";

                //envelope.bodyOut=body;

                androidHttpTransport = new AndroidHttpTransport (URL); 
                androidHttpTransport.debug = true;
                //androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

                androidHttpTransport.call(SOAP_ACTION, envelope);
                Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
                ((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
            } catch(Exception E) {
                Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
                ((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump+"ERROR:" +"\r\n\r\n" +androidHttpTransport.responseDump  +"\r\n\r\n" +E.getClass().getName() + ": " + E.getMessage());
            }
    }



}

据我所知,问题是由 envelope.addMapping(null, "scanItem",new Scan().getClass()); 行引起的,甚至当我删除了“scanItem”部分,它仍然生成

任何帮助解决这个问题的帮助都会很棒。

I am using the envelope.addMapping function in ksoap2 and I need to make it generate items with no i:type attribute.

This is the soap request my code generates

<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>
        <ApiKey xmlns="urn:example:data">APIKey</ApiKey>
    </v:Header>
    <v:Body>
        <CreateScan xmlns="urn:example:services" id="o0" c:root="1">
            <scan i:type="n3:" xmlns:n3="">
                <n4:BaseUrl i:type="d:string" xmlns:n5="urn:example:data">http://www.example.com</n5:BaseUrl>
                <n5:DisplayName i:type="d:string" xmlns:n7="urn:example:data">Example Scan</n7:DisplayName>
            </scan>
        </CreateScan>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I need to make it so <scan i:type="n3:scanItem" xmlns:n3=""> is generated as <scan>

Here is my code

package ksoap2.test;

import java.util.Hashtable;
import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class ksoap2 extends Activity {
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION = "http://example.com/OperationsService.svc";
    private static final String METHOD_NAME = "CreateScan";
    private static final String NAMESPACE = "urn:example:services";
    private static final String URL = "http://example.com/OperationsService.svc";
    private AndroidHttpTransport androidHttpTransport;
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.textView1);

        try {
            Element ApiKeyElement = new Element().createElement("", "ApiKey");
            ApiKeyElement.setAttribute("", "xmlns", "urn:example:data");
            ApiKeyElement.addChild(Node.TEXT, "22DF0959F20743660304CB829B3891F0");


            Element[] header = new Element[1];
            header[0]=ApiKeyElement;


            Element request = new Element().createElement(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);          
//              PropertyInfo scanProp = new PropertyInfo();
//              scanProp.setName("scan");
//              scanProp.setValue("");

                SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
                Scan s = new Scan();
                s.BaseUrl="http://www.example.com";
                s.DisplayName="Example";

                PropertyInfo pi = new PropertyInfo();
                pi.setName("scan");
                pi.setValue(s);
                pi.setType(s.getClass());
                Request.addProperty(pi);

                //request.addChild(Node.ELEMENT, scanElement);
                envelope.headerOut = header;
                //envelope.dotNet = true;
                envelope.setOutputSoapObject(Request);

                envelope.addMapping(null, "scanItem",new Scan().getClass());
                envelope.dotNet =false;
                String BodyClass = envelope.bodyOut.getClass().toString();
                SoapObject body = (SoapObject)envelope.bodyOut;
                int count =body.getPropertyCount();
                //envelope.encodingStyle = "test";

                //envelope.bodyOut=body;

                androidHttpTransport = new AndroidHttpTransport (URL); 
                androidHttpTransport.debug = true;
                //androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

                androidHttpTransport.call(SOAP_ACTION, envelope);
                Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
                ((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
            } catch(Exception E) {
                Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
                ((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump+"ERROR:" +"\r\n\r\n" +androidHttpTransport.responseDump  +"\r\n\r\n" +E.getClass().getName() + ": " + E.getMessage());
            }
    }



}

From what I can tell the issue arises from the envelope.addMapping(null, "scanItem",new Scan().getClass()); line and even when I remove the "scanItem" part it still generates <scan i:type="n3:" xmlns:n3="">

Any help figuring this out would be amazing.

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

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

发布评论

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

评论(1

鸵鸟症 2024-11-01 18:05:46

好吧,看来我回答了我自己的问题。我所要做的就是添加行 envelope.implicitTypes = true;

Well it looks like I answered my own question. All I had to do was add the line envelope.implicitTypes = true;

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