使用不带“i:type="的 addMappingksoap2 for android 中的属性 [英] using addMapping without the "i:type=" attribute in ksoap2 for android

查看:16
本文介绍了使用不带“i:type="的 addMappingksoap2 for android 中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是我的代码生成的soap请求

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>

这是我的代码

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 +"

" + androidHttpTransport.responseDump);
                ((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump +"

" + androidHttpTransport.responseDump);
            } catch(Exception E) {
                Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"

" + androidHttpTransport.responseDump);
                ((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump+"ERROR:" +"

" +androidHttpTransport.responseDump  +"

" +E.getClass().getName() + ": " + E.getMessage());
            }
    }



}

据我所知,问题出自 envelope.addMapping(null, "scanItem",new Scan().getClass()); 行,即使我删除了scanItem"它仍然生成 <scan i:type="n3:" xmlns:n3="">

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.

推荐答案

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

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

这篇关于使用不带“i:type="的 addMappingksoap2 for android 中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆