Java Webservice将null对象返回到.net客户端

Chk*_*uke 5 .net java web-services

任何人都能弄清楚我的问题是......

我正在从.Net客户端调用Java Webservice(Axis 1.4)的web方法.该方法返回一个Map对象,如果我从Axis客户端调用它工作正常,但在我的c#代码中它总是为null.

这是WSDL:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:http.service.enlaces.portlet.ext.com" xmlns:intf="urn:http.service.enlaces.portlet.ext.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://model.enlaces.portlet.ext.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:http.service.enlaces.portlet.ext.com">

<wsdl:types>

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.apache.org/xml-soap">
<import namespace="urn:http.service.enlaces.portlet.ext.com"/>
<import namespace="http://model.enlaces.portlet.ext.com"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="mapItem">
   <sequence>
 <element name="key" nillable="true" type="xsd:anyType"/>
 <element name="value" nillable="true" type="xsd:anyType"/>
   </sequence>
</complexType>
<complexType name="Map">
   <sequence>
   <element maxOccurs="unbounded" minOccurs="0" name="item" type="apachesoap:mapItem"/>
   </sequence>
</complexType>   
</schema>
 </wsdl:types>

<wsdl:message name="getFoldersAndBookmarksRequest" />
<wsdl:message name="getFoldersAndBookmarksResponse">
    <wsdl:part name="getFoldersAndBookmarksReturn" type="apachesoap:Map" />
</wsdl:message>

<wsdl:portType name="BookmarksEntryServiceSoap">
<wsdl:operation name="getFoldersAndBookmarks">
      <wsdl:input name="getFoldersAndBookmarksRequest"  message="intf:getFoldersAndBookmarksRequest" />
      <wsdl:output name="getFoldersAndBookmarksResponse" message="intf:getFoldersAndBookmarksResponse" />
    </wsdl:operation>
  </wsdl:portType>

<wsdl:binding name="Portlet_Bookmarks_BookmarksEntryServiceSoapBinding" type="intf:BookmarksEntryServiceSoap">
    <wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
  <wsdl:operation name="getFoldersAndBookmarks">
      <wsdlsoap:operation soapAction="" />
      <wsdl:input name="getFoldersAndBookmarksRequest">
        <wsdlsoap:body use="encoded" namespace="urn:http.service.enlaces.portlet.ext.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:input>
      <wsdl:output name="getFoldersAndBookmarksResponse">
        <wsdlsoap:body use="encoded" namespace="urn:http.service.enlaces.portlet.ext.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
Run Code Online (Sandbox Code Playgroud)

和我的c#自动生成的代码:

[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:http.service.enlaces.portlet.ext.com", ResponseNamespace="urn:http.service.enlaces.portlet.ext.com")]
[return: System.Xml.Serialization.SoapElementAttribute("getFoldersAndBookmarksReturn")]
public Map getFoldersAndBookmarks() {
    object[] results = this.Invoke("getFoldersAndBookmarks", new object[0]);
    return ((Map)(results[0]));
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="http://xml.apache.org/xml-soap")]
public partial class Map {

    private mapItem[] itemField;

    /// <comentarios/>
    public mapItem[] item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我到处都看到了,我找不到解决办法.拜托,有谁知道呢?

Kar*_*l P 0

这就是为什么从代码生成的 Web 服务几乎无法互操作:)

解决这个问题的一个好方法是首先制作 wsdl,并定义一个清晰的 XSD,它应该很好地映射到 .Net 和 java。如果您对此有任何控制权,则另一种选择是服务器的 axis 1.4(是的,痛苦)之外的其他东西。

最后,尝试调整 java 代码中的签名,尝试用 MapItem[] 替换 List,反之亦然,确保返回对象或参数中的任何位置都没有 Map。

再次查看生成的 wsdl,我想说这可能是因为 mapItem 的键/值部分的 xsd:anyType 。

我认为如果参数中有一个 java 对象,这就是 axis 生成的内容。相信我,你不会想要这样的。使其成为字符串、复杂类型或整数,但对象只能表示开放式 xml (xsd:anyType),并且没有多少客户端不知道如何解析它。