2010-09-02 76 views
0

从使用KSOAP向J2ME客户端发送复杂对象数组到.NET Web服务(Soap服务)时,我遇到了一个问题。使用kso​​ap2向.NET Web服务发送复杂对象数组

我TestSoap.java文件具有setArr()方法,该方法采用PropHeaderMapBin对象的阵列,并且将其发送到其返回一个整数(PropHeaderMapBin对象的计数)setArr的

TestSoap.java 

package org.tempuri; 

    import com.n9ciphers.test.Constants; 
    import java.util.Vector; 
    import org.ksoap2.SoapEnvelope; 
    import org.ksoap2.serialization.PropertyInfo; 
    import org.ksoap2.serialization.SoapObject; 
    import org.ksoap2.serialization.SoapSerializationEnvelope; 
    import org.ksoap2.transport.HttpTransport; 
    import org.tempuri.PropHeaderMapBin; 

    public final class TestSoap { 

     public int setArr(PropHeaderMapBin[] inArr) throws Exception { 

      SoapObject _client = new SoapObject("http://tempuri.org/", "SetArr"); 
      SoapObject[] _propHeaderMapBinSO = new SoapObject[inArr.length]; 

      PropHeaderMapBin[] prop = inArr; 
      //PropHeaderMapBin[] prop = new PropHeaderMapBin[inArr.length]; 
      Vector _propVector = new Vector(inArr.length); 
      if (inArr != null) { 

       //System.out.println("_len " + inArr.length); 

       for (int i = 0; i < inArr.length; i++) { 
        _propHeaderMapBinSO[i] = new SoapObject("http://tempuri.org/", "PropHeaderMapBin"); 
        _propHeaderMapBinSO[i].addProperty("PropertyName", prop[i].getPropertyName()); 
        _propHeaderMapBinSO[i].addProperty("value", prop[i].getValue()); 
        _propHeaderMapBinSO[i].addProperty("HeaderText", prop[i].getHeaderText()); 
        _propHeaderMapBinSO[i].addProperty("label", prop[i].getLabel()); 

        _propVector.addElement(_propHeaderMapBinSO[i]); 
       } 
      } 

      _client.addProperty(pi, _propVector); 

      SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      _envelope.addMapping("http://www.tempuri.org/", "PropHeaderMapBin", new PropHeaderMapBin().getClass()); 
      //_envelope.addTemplate (_client); 
      _envelope.bodyOut = _client; 
      _envelope.dotNet = true; 

      HttpTransport _ht = new HttpTransport(Constants.endPoint + "Test.asmx"); 
      _ht.debug = true; 
      _ht.call("http://tempuri.org/SetArr", _envelope); 

      //System.out.println("response: " + result.toString()); 

      System.out.println("Request Dump:" + _ht.requestDump); 
      //Dialog.show("Request Dump", _ht.requestDump, Dialog.TYPE_INFO, null, "OK", null); 
      System.out.println("Response Dump:" + _ht.responseDump); 
      //Dialog.show("Response Dump", _ht.responseDump, Dialog.TYPE_INFO, null, "OK", null); 

      return Integer.parseInt(_envelope.getResponse().toString()); 
      //return 0; 
     } 
    } 

输出的web服务( )方法调用。的服务器不能识别在阵列的对象的数据类型,并将其设置到数组类型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 

我的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> 

我如果有人已经面对这样的问题并成功地解决了这个问题,那么武汉市就会很感激。

+0

user435696:您是否找到解决此问题的解决方案?我有同样的问题。你的信息帮助了我很多。 – 2011-02-01 13:39:54

+0

这是什么解决方案?我尝试了soapUI,但似乎无法发现ksoap2和s soapUI请求之间的任何重大差异 – AhmedW 2011-02-01 13:40:02

回答

1

我可以给你提示解决问题。

使用soapUI工具创建具有相同WSDL的Web服务项目(它非常容易和快速)。

将您的请求转储与soapUI生成的soap body进行比较。你会发现差异和

因此的解决方案。

0

@Rajnikant有它现货。如果您有无法使用的Web服务,请使用SOAPui导入wsdl端点。这将为您可以用来调用您的wcf方法并查看请求转储的方法创建一个测试工具。将此与来自移动设备的请求转储(使用androidHttpTransport.requestDump)进行比较.....请注意传递的参数及其命名空间....这非常重要

相关问题