Question

Im creating a JAX-WS webservice on Wildfly 8.0 and consuming it on a VS2013 C# project, what I can't figure out is how can I map a HashMap to .net Dictionary.

My question is, is there a way to create a JAX-WS webservice that is compatible with the .net Dictionary and its automatically converted by the "Add service reference"?

"Add service reference" advanced settings: enter image description here

Test webservice:

@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>();
    }
}

Generated 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>
Was it helpful?

Solution

I don't think HashMap is interoperable; it also isn't a Java xml type known to JAXB (the framework which turns SOAP XML into java instances which is probably why it's not described in the WSDL.

You can use the tips in this post to provide an adapter Java class which tells the JAXB runtime how to convert your HashMap into an xml structure.

However, I doubt this will be natively consumed by a .Net client as Dictionary. You could try to produce the xml structure described in this article from your Java adapter in the hopes that it will be interpreted as Dictionary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top