简体   繁体   中英

Best way to consume .NET web services in Java

I'm trying to consume some .NET web services using JAX-WS. I have generated the Java classes using the wsimport tool. However, when I try to use these (proprietary, not public) web services in Java, I notice that most of the methods and properties provided by the vendor in their C# examples are not avaiable in the generated classes (despite having not encountered any errors when generating the Java classes from WSDL file). Connecting to the web services also works basically.

When I tried to generate a C# class using wsdl.exe from the .NET SDK, all the methods were properly generated.

What would be the best way to consume the .NET web services so that the full functionality would be available in Java, and why does wsimport only generate a small subset of all the methods and properties described in the WSDL file?

Example: in the WSDL file UserManagement.wsdl there is a snippet


<s:schema elementFormDefault="qualified" targetNamespace="http://www.initechsystems.com/initech7/initechws/">
  <s:element name="UserSecurityContext" type="s2:UserSecurityContext"/>
  <s:complexType name="UserSecurityContext">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Token" type="s2:UserToken"/>
    </s:sequence>
  </s:complexType>
  <s:complexType name="UserToken">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Value" type="s:string"/>
    </s:sequence>
  </s:complexType>
</s:schema>

In C#, I can access the the UserSecurityContext followingly:


UserManagement userMgmt = new UserManagement();
userMgmt.UserSecurityContextValue = new SampleWS.UserRef.UserSecurityContext();
However, in Java I can create the UserManagement object

 UserManagement userMgmt = new UserManagement(); 

but the generated UserManagement object does not have any accessible object SecurityContext, nor getters or setters for such a private object.

I would like to see the example you are talking about, as it sounds like the example sends objects with behavior across the wire rather than just models (or messages, if you would prefer a better SOA term).

When you send an object that is formated as a data model, or message, it will not contain methods to use. And, with interop, it does not make a lot of sense to set up behavior (methods) to go across the wire.

As for what you can do, since you are serializing, you can create the behavioral methods, if they make sense on your side. Personally, I would create the behavior in other objects and keep the models/messages as state containers. But, your mileage may vary. ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM