简体   繁体   English

如何使用SOAP将XML请求发送到Java中的Web服务?

[英]How to send XML request to webservice in java using SOAP?

I am supposed to send a XML request to this webservice which return a XML response and then I can use that XML response on my side. 我应该向该Web服务发送XML请求,该请求将返回XML响应,然后可以在我这一侧使用该XML响应。 This is a USPS shipping label request through endicia. 这是通过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>

How to send this request and receive response? 如何发送此请求并接收响应?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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