简体   繁体   中英

Consuming a .NET web service from a Java Soap Client?

I'm looking for a simple way to construct a soap request in order to consume a .NET web service, but i found little to no documentation at all regarding this subject. The default library javax.xml.soap is more than ambiguous in how to construct the request.

Are there any libraries available that will make my life easier?

I found this piece of code somewhere, and i don't now how it's used or what library it's from, but i would very much like something similar, instead of constructing the entire xml message manually using DOM, or something similar (because it takes the Simple out of SOAP)

SoapRequestBuilder s = new SoapRequestBuilder();
s.Server = "127.0.0.1"; // server ip address or name

s.MethodName = "ConcatWithSpace";
s.XmlNamespace = "http://tempuri.org/";
s.WebServicePath = "/SimpleService/Service1.asmx";
s.SoapAction = s.XmlNamespace+s.MethodName;
s.AddParameter("one", "David");
s.AddParameter("two", "Hobbs");
String response = s.sendRequest();

This is the message form that i have to send:

POST /webservice/TimrService.asmx HTTP/1.1
Host: not.important.host
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetTimetableForBachelorYear"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetTimetableForBachelorYear xmlns="http://tempuri.org/">
      <year>I1</year>
      <halfYear>A</halfYear>
    </GetTimetableForBachelorYear>
  </soap:Body>
</soap:Envelope>

I'm a .NET developer myself, but we have a 3rd party integration with a team of Java developers consuming one of our services, and I hear them often refer to a code-generation tool called wsdl2java and a testing interface called SOAPUI . I'm thinking it might be something like this: http://cxf.apache.org/docs/wsdl-to-java.html . If I understand it correctly, it works a little bit like adding a web service reference in .NET, by generating classes that take care of all the SOAP calls automatically. You just have to call the right methods and pass in the parameters.

查看http://docs.oracle.com/javaee/1.4/tutorial/doc/SAAJ4.html以获得一个很好的SAAJ示例。

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