如何使用SOAP将XML请求发送到java中的webservice?

时间:2013-11-13 08:04:01

标签: java xml web-services soap

我应该向这个返回XML响应的web服务发送一个XML请求,然后我可以在我这边使用该XML响应。这是通过endicia的USPS运输标签请求。

POST /LabelService/EwsLabelService.asmx HTTP/1.1
Host: www.envmgr.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "www.envmgr.com/LabelService/GetPostageLabel"



<?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>
<GetPostageLabel xmlns="www.envmgr.com/LabelService">
<LabelRequest Test="YES" LabelType="Default" LabelSize="4X6" ImageFormat="GIF"> 
<RequesterID>abcd</RequesterID> 
<AccountID>123456</AccountID> 
<PassPhrase>samplePassPhrase</PassPhrase> 
<MailClass>Priority</MailClass> 
<DateAdvance>0</DateAdvance> 
<WeightOz>15</WeightOz> 
<MailpieceShape>Parcel</MailpieceShape> 
<Stealth>FALSE</Stealth> 
<Services InsuredMail="OFF" DeliveryConfirmation=\u201dON\u201d SignatureConfirmation="ON" /> 
<Value>0</Value> 
<Description>Sample Label</Description> 
<PartnerCustomerID>12345ABCD</PartnerCustomerID> 
<PartnerTransactionID>6789EFGH</PartnerTransactionID> 
<ToName>Label Server Support</ToName> 
<ToCompany>Endicia</ToCompany> 
<ToAddress1>385 Sherman Ave.</ToAddress1> 
<ToCity>Palo Alto</ToCity> 
<ToState>CA</ToState> 
<ToPostalCode>94306</ToPostalCode> 
<ToZIP4>1864</ToZIP4> 
<ToDeliveryPoint>00</ToDeliveryPoint> 
<ToPhone>8005763279</ToPhone> 
<FromName>Benjamin Franklin</FromName> 
<ReturnAddress1>475 Enfant Plaza SW</ReturnAddress1> 
<FromCity>Washington</FromCity> 
<FromState>DC</FromState> 
<FromPostalCode>20260</FromPostalCode> 
<FromZIP4>0004</FromZIP4> 
<FromPhone>2025551212</FromPhone> 
<ResponseOptions PostagePrice="TRUE"/> 
</LabelRequest> 
</GetPostageLabel>
</soap:Body>
</soap:Envelope>

如何发送此请求并收到回复?

1 个答案:

答案 0 :(得分:2)

如果您想自己构建soap内容,可以使用URLConnection类发送http请求,或者您可以使用CXF框架,这将帮助您将Web服务转换为Java接口。