java - JAX-WS HashMap 和 .NET 字典的互操作性

标签 java .net web-services soap jax-ws

我在 Wildfly 8.0 上创建一个 JAX-WS Web 服务,并在 VS2013 C# 项目上使用它,我不知道如何将 HashMap 映射到 .net 字典。

我的问题是,有没有办法创建一个与 .net 词典兼容的 JAX-WS Web 服务,并通过“添加服务引用”自动转换它?

“添加服务引用”高级设置: enter image description here

测试网络服务:

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class Test
{    
    @WebMethod
    public HashMap<String, Pojo> echoMap(String input)
    {
        return new HashMap<String, Pojo>();
    }
}

生成的 WSDL:

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.aiko.com/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="TestService" targetNamespace="http://ws.aiko.com/">
  <wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.aiko.com/" targetNamespace="http://ws.aiko.com/" version="1.0">

  <xs:element name="facility" type="tns:pojo"/>

  <xs:complexType name="pojo">
    <xs:sequence>
      <xs:element minOccurs="0" name="Name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
  </wsdl:types>
  <wsdl:message name="echoMapResponse">
    <wsdl:part name="return">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="echoMap">
    <wsdl:part name="arg0" type="xsd:string">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="Test">
    <wsdl:operation name="echoMap">
      <wsdl:input message="tns:echoMap" name="echoMap">
    </wsdl:input>
      <wsdl:output message="tns:echoMapResponse" name="echoMapResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="TestServiceSoapBinding" type="tns:Test">
    <soap12:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="echoMap">
      <soap12:operation soapAction="" style="rpc"/>
      <wsdl:input name="echoMap">
        <soap12:body namespace="http://ws.aiko.com/" use="literal"/>
      </wsdl:input>
      <wsdl:output name="echoMapResponse">
        <soap12:body namespace="http://ws.aiko.com/" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="TestService">
    <wsdl:port binding="tns:TestServiceSoapBinding" name="TestPort">
      <soap12:address location="http://localhost:8080/app/Test"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

最佳答案

我不认为HashMap是可互操作的;它也不是 JAXB 已知的 Java xml 类型(该框架将 SOAP XML 转换为 java 实例,这可能就是 WSDL 中没有描述它的原因。

您可以使用 this post 中的提示提供一个适配器 Java 类,告诉 JAXB 运行时如何将 HashMap 转换为 xml 结构。

但是,我怀疑 .Net 客户端是否会将其作为 Dictionary 本地使用。您可以尝试生成 this article 中描述的 xml 结构。来自您的 Java 适配器,希望它将被解释为字典。

关于java - JAX-WS HashMap 和 .NET 字典的互操作性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22722220/

相关文章:

java - EnableWebMvc 抛出 ServletException : Could not resolve view with name

java - 在 JNI 中修改的 Mat 不反射(reflect)在 Java 中的更改

ASP.Net 哪个用户帐户在 IIS 7 上运行 Web 服务?

java - SpringBoot MVC - 警告 : org. apache.tomcat.util.net.SSLUtilBase : The JSSE TLS 1. 3 实现不支持身份验证

java - 如何在android私有(private)库中添加jar文件?

c# - 在 SSH.NET 中进行多因素身份验证( key 和密码)时获取 'Permission denied (password).'

c# - WCF 4.0 - 使用 REST 服务模板返回 JSON WebFaultException

c# - 系统.反射;生成(某种类型的)字段列表

web-services - RESTful API 设计 : best way to CRUD lightweight connections?

c# - 许多 WebReferences 使用相同的类