使用ksoap2将复杂对象数组发送到.NETWeb服务

使用ksoap2将复杂对象数组发送到.NETWeb服务,.net,web-services,java-me,ksoap2,.net,Web Services,Java Me,Ksoap2,在使用KSOAP从J2ME客户机向.NETWeb服务(Soap服务)发送复杂对象数组时,我遇到了一个问题 我的TestSoap.java文件有一个setArr()方法,它接受PropHeaderMapBin对象的数组并将其发送到web服务,web服务返回一个整数(PropHeaderMapBin对象的计数) TestSoap.java 包org.tempuri; 导入com.n9ciphers.test.Constants; 导入java.util.Vector; 导入org.ksoap2.So

在使用KSOAP从J2ME客户机向.NETWeb服务(Soap服务)发送复杂对象数组时,我遇到了一个问题

我的TestSoap.java文件有一个setArr()方法,它接受PropHeaderMapBin对象的数组并将其发送到web服务,web服务返回一个整数(PropHeaderMapBin对象的计数)

TestSoap.java
包org.tempuri;
导入com.n9ciphers.test.Constants;
导入java.util.Vector;
导入org.ksoap2.SoapEnvelope;
导入org.ksoap2.serialization.PropertyInfo;
导入org.ksoap2.serialization.SoapObject;
导入org.ksoap2.serialization.SoapSerializationEnvelope;
导入org.ksoap2.transport.HttpTransport;
导入org.tempuri.mapbin;
公共最终类TestSoap{
public int setArr(PropHeaderMapBin[]inArr)引发异常{
SoapObject _client=新的SoapObject(“http://tempuri.org/“,“SetArr”);
SoapObject[]_-mapbino=新的SoapObject[inArr.length];
PropHeaderMapBin[]prop=inArr;
//PropHeaderMapBin[]prop=新PropHeaderMapBin[inar.length];
向量_propVector=新向量(初始长度);
如果(inArr!=null){
//系统输出打印长度(“_len”+长度);
对于(int i=0;i
setArr()方法调用的输出。服务器无法识别数组中对象的数据类型,它将arraytype设置为anytype[3],并返回0而不是3

Request Dump:
<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>
        <SetArr xmlns="http://tempuri.org/" id="o0" c:root="1">
            <inArr i:type="c:Array" c:arrayType="d:anyType[3]">
                <item i:type="n0:PropHeaderMapBin" xmlns:n0="http://tempuri.org/">
                    <PropertyName i:type="d:string">1</PropertyName>
                    <value i:type="d:string">1</value>
                    <HeaderText i:type="d:string">Pradhan</HeaderText>
                    <label i:type="d:string">Pradhan</label>
                </item>
                <item i:type="n1:PropHeaderMapBin" xmlns:n1="http://tempuri.org/">
                    <PropertyName i:type="d:string">2</PropertyName>
                    <value i:type="d:string">2</value>
                    <HeaderText i:type="d:string">Kavya</HeaderText>
                    <label i:type="d:string">Kavya</label>
                </item>
                <item i:type="n2:PropHeaderMapBin" xmlns:n2="http://tempuri.org/">
                    <PropertyName i:type="d:string">3</PropertyName>
                    <value i:type="d:string">3</value>
                    <HeaderText i:type="d:string">Puchi</HeaderText>
                    <label i:type="d:string">Puchi</label>
                </item>
            </inArr>
        </SetArr>
    </v:Body>
</v:Envelope>


Response Dump:<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <SetArrResponse xmlns="http://tempuri.org/">
            <SetArrResult>0</SetArrResult>
        </SetArrResponse>
    </soap:Body>
</soap:Envelope>
response = 0
请求转储:
1.
1.
普拉丹
普拉丹
2.
2.
卡维亚
卡维亚
3.
3.
普奇
普奇
响应转储:
0
响应=0
我的wsdl文件供参考

<wsdl:definitions targetNamespace="http://tempuri.org/">
    <wsdl:types>
        <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
            <s:element name="GetArr">
                <s:complexType/>
            </s:element>
            <s:element name="GetArrResponse">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" name="GetArrResult" type="tns:ArrayOfPropHeaderMapBin"/>
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:complexType name="ArrayOfPropHeaderMapBin">
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="unbounded" name="PropHeaderMapBin" nillable="true" type="tns:PropHeaderMapBin"/>
                </s:sequence>
            </s:complexType>
            <s:complexType name="PropHeaderMapBin">
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="1" name="PropertyName" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="value" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="HeaderText" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="label" type="s:string"/>
                </s:sequence>
            </s:complexType>
            <s:element name="SetArr">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" name="inArr" type="tns:ArrayOfPropHeaderMapBin"/>
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:element name="SetArrResponse">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="1" maxOccurs="1" name="SetArrResult" type="s:int"/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:schema>
    </wsdl:types>
    <wsdl:message name="GetArrSoapIn">
        <wsdl:part name="parameters" element="tns:GetArr"/>
    </wsdl:message>
    <wsdl:message name="GetArrSoapOut">
        <wsdl:part name="parameters" element="tns:GetArrResponse"/>
    </wsdl:message>
    <wsdl:message name="SetArrSoapIn">
        <wsdl:part name="parameters" element="tns:SetArr"/>
    </wsdl:message>
    <wsdl:message name="SetArrSoapOut">
        <wsdl:part name="parameters" element="tns:SetArrResponse"/>
    </wsdl:message>
    <wsdl:portType name="TestSoap">
        <wsdl:operation name="GetArr">
            <wsdl:input message="tns:GetArrSoapIn"/>
            <wsdl:output message="tns:GetArrSoapOut"/>
        </wsdl:operation>
        <wsdl:operation name="SetArr">
            <wsdl:input message="tns:SetArrSoapIn"/>
            <wsdl:output message="tns:SetArrSoapOut"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="TestSoap" type="tns:TestSoap">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="HelloWorld">
            <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetArr">
            <soap:operation soapAction="http://tempuri.org/GetArr" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="SetArr">
            <soap:operation soapAction="http://tempuri.org/SetArr" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="TestSoap12" type="tns:TestSoap">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="GetArr">
            <soap12:operation soapAction="http://tempuri.org/GetArr" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="SetArr">
            <soap12:operation soapAction="http://tempuri.org/SetArr" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="Test">
        <wsdl:port name="TestSoap" binding="tns:TestSoap">
            <soap:address location="http://xxx.xxx.xxx.xxx/Services/Test.asmx"/>
        </wsdl:port>
        <wsdl:port name="TestSoap12" binding="tns:TestSoap12">
            <soap12:address location="http://xxx.xxx.xxx.xxx/Services/Test.asmx"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>


如果有人已经遇到这种问题并成功地解决了它,我将非常感谢您的帮助。

我可以给您一些解决问题的提示

使用soapUI工具创建具有相同WSDL的web服务项目(非常简单和快速)

将请求转储与soapUI生成的soap正文进行比较。你会发现其中的差别并


这就是解决方案。

@Rajnikant已经找到了答案。如果您的wcf web服务不工作,请使用SOAPui导入wsdl端点。这将为方法创建一个测试工具,然后您可以使用该工具调用wcf方法并查看请求转储。比较
<wsdl:definitions targetNamespace="http://tempuri.org/">
    <wsdl:types>
        <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
            <s:element name="GetArr">
                <s:complexType/>
            </s:element>
            <s:element name="GetArrResponse">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" name="GetArrResult" type="tns:ArrayOfPropHeaderMapBin"/>
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:complexType name="ArrayOfPropHeaderMapBin">
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="unbounded" name="PropHeaderMapBin" nillable="true" type="tns:PropHeaderMapBin"/>
                </s:sequence>
            </s:complexType>
            <s:complexType name="PropHeaderMapBin">
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="1" name="PropertyName" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="value" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="HeaderText" type="s:string"/>
                    <s:element minOccurs="0" maxOccurs="1" name="label" type="s:string"/>
                </s:sequence>
            </s:complexType>
            <s:element name="SetArr">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="0" maxOccurs="1" name="inArr" type="tns:ArrayOfPropHeaderMapBin"/>
                    </s:sequence>
                </s:complexType>
            </s:element>
            <s:element name="SetArrResponse">
                <s:complexType>
                    <s:sequence>
                        <s:element minOccurs="1" maxOccurs="1" name="SetArrResult" type="s:int"/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:schema>
    </wsdl:types>
    <wsdl:message name="GetArrSoapIn">
        <wsdl:part name="parameters" element="tns:GetArr"/>
    </wsdl:message>
    <wsdl:message name="GetArrSoapOut">
        <wsdl:part name="parameters" element="tns:GetArrResponse"/>
    </wsdl:message>
    <wsdl:message name="SetArrSoapIn">
        <wsdl:part name="parameters" element="tns:SetArr"/>
    </wsdl:message>
    <wsdl:message name="SetArrSoapOut">
        <wsdl:part name="parameters" element="tns:SetArrResponse"/>
    </wsdl:message>
    <wsdl:portType name="TestSoap">
        <wsdl:operation name="GetArr">
            <wsdl:input message="tns:GetArrSoapIn"/>
            <wsdl:output message="tns:GetArrSoapOut"/>
        </wsdl:operation>
        <wsdl:operation name="SetArr">
            <wsdl:input message="tns:SetArrSoapIn"/>
            <wsdl:output message="tns:SetArrSoapOut"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="TestSoap" type="tns:TestSoap">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="HelloWorld">
            <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetArr">
            <soap:operation soapAction="http://tempuri.org/GetArr" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="SetArr">
            <soap:operation soapAction="http://tempuri.org/SetArr" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="TestSoap12" type="tns:TestSoap">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="GetArr">
            <soap12:operation soapAction="http://tempuri.org/GetArr" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="SetArr">
            <soap12:operation soapAction="http://tempuri.org/SetArr" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="Test">
        <wsdl:port name="TestSoap" binding="tns:TestSoap">
            <soap:address location="http://xxx.xxx.xxx.xxx/Services/Test.asmx"/>
        </wsdl:port>
        <wsdl:port name="TestSoap12" binding="tns:TestSoap12">
            <soap12:address location="http://xxx.xxx.xxx.xxx/Services/Test.asmx"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>