【发布时间】:2012-05-31 13:10:19
【问题描述】:
我正在寻找一种简单的方法来构造一个soap 请求以使用一个.NET web 服务,但我发现几乎没有关于这个主题的文档。默认库 javax.xml.soap 在如何构造请求方面非常含糊。
是否有任何可用的库可以让我的生活更轻松?
我在某处找到了这段代码,我现在不知道它是如何使用的,也不知道它来自什么库,但我非常想要类似的东西,而不是使用 DOM 或类似的东西手动构建整个 xml 消息(因为它把 SOAP 中的 Simple 去掉了)
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>
【问题讨论】:
标签: java .net xml soap request