2012-05-24 146 views
3

我正在寻找一种简单的方法来构建一个SOAP请求,以便使用.NET Web服务,但是我发现几乎没有关于此主题的文档。默认的库javax.xml.soap在构造请求方面比模糊不清。从Java Soap客户端使用.NET Web服务?

是否有任何图书馆可以让我的生活更轻松?

我发现这段代码在某处,我现在不知道它是如何使用的或者它来自哪个库,但我非常想类似的东西,而不是使用DOM手动构建整个xml消息,或类似的东西(因为它需要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(); 

这是我要发送邮件形式:

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> 

回答

3

我.NET开发自己,但我们有一个第三方与一组Java开发人员一起使用我们的服务之一,我听说他们经常提到称为wsdl2java的代码生成工具和称为SOAPUI的测试界面。我在想这可能是这样的:http://cxf.apache.org/docs/wsdl-to-java.html。如果我正确地理解了它,它有点像在.NET中添加Web服务引用,它通过生成自动处理所有SOAP调用的类。你只需要调用正确的方法并传入参数。