[英]Consuming in Java a .NET Web Service that requires a custom SOAP Header
因此,我需要使用一個使用自定義SoapHeader的Web服務,如下所述。 使用Java通過此標頭傳遞正確值的最簡單方法是什么。 我正在使用Netbeans。
<?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:Header>
<CustomSoapHeader xmlns="http://snip">
<UserName>"string"</UserName>
<Password>"string"</Password>
</CustomSoapHeader>
</soap:Header>
<soap:Body>
<SomeWebMethod xmlns="http://snip" />
</soap:Body>
</soap:Envelope>
編輯:在堆棧溢出上顯示XML的最佳方法是什么?
添加Web服務是在.NET中實現的,可能會有所幫助,並且我無法更改服務器端代碼。
假設您是在客戶端執行以下步驟,請按照以下基本步驟操作:
您可以通過請求上下文將參數傳遞給處理程序:
Map<String, Object> context = ((BindingProvider) port).getRequestContext();
context.put("userName', "foo");
...
在handleMessage()中,您可以像這樣獲得標題:
public boolean handleMessage(SOAPMessageContext context) {
...
SOAPMessage msg = context.getMessage();
msg.getSoapHeader();
...
}
希望能有所幫助。 我猜也有一種方法可以通過注釋來完成這些工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.