scala 如何将身份验证标头传递给 JAXWS SOAP 客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12671526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass Authentication Header to JAXWS SOAP client
提问by Sergey
I have generated classes for soap client using wsimport.exe.
我已经使用 wsimport.exe 为soap 客户端生成了类。
My request should look like
我的请求应该看起来像
POST /posaservice/servicemanager.asmx HTTP/1.1
Host: ****
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.pininteract.com/BalanceInquiry"
<?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>
<AuthenticationHeader xmlns="http://www.pininteract.com">
<userId>VALUE</userId>
<password>VALUE</password>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<BalanceInquiry xmlns="http://www.pininteract.com" />
</soap:Body>
</soap:Envelope>
But I don't know how to pass parameters to Authentication Header part. Currently my code looks like
但我不知道如何将参数传递给 Authentication Header 部分。目前我的代码看起来像
val client = new ServiceManager().getServiceManagerSoap()
var res = client.balanceInquiry()
println(res)
I have class AuthenticationHeader among others generated, but I don't know how to use it.
我生成了 AuthenticationHeader 类,但我不知道如何使用它。
采纳答案by Sergey
Actually after more search through stackoverflow I found solution to my problem How do I add a SOAP Header using Java JAX-WS
实际上,在通过 stackoverflow 进行更多搜索后,我找到了问题的解决方案 How do I add a SOAP Header using Java JAX-WS
回答by kanaparthikiran
I could not find a better solution than this using JAX-WS.
我找不到比使用 JAX-WS 更好的解决方案。
You can send any header using this approach.
您可以使用这种方法发送任何标头。
wsimport -keep -verbose -XadditionalHeaders https:// yourWebService ? WSDL
wsimport -keep -verbose -XadditionalHeaders https:// yourWebService ?WSDL
When You generate the WebService clients using "XadditionalHeaders", this will generate the Stub/Port methods with the Header as one of the method Parameters, which You can set just like any parameters.
当您使用“XadditionalHeaders”生成 WebService 客户端时,这将生成 Stub/Port 方法,其中 Header 作为方法参数之一,您可以像设置任何参数一样设置这些方法。
Info sysInfoOne = siOne.doGetSystemInfo(YourParam); becomes
信息 sysInfoOne = siOne.doGetSystemInfo(YourParam); 变成
Info sysInfoOne = siOne.doGetSystemInfo(YourParam, YourAnyTypeOfHeader); Reference - JAXWS Specification.
信息 sysInfoOne = siOne.doGetSystemInfo(YourParam, YourAnyTypeOfHeader); 参考 - JAXWS 规范。
And this is what Developers like to do, rather than editing/sending the XML.
这就是开发人员喜欢做的,而不是编辑/发送 XML。
Other Approaches I tried were - adding a JAX-WS Client Handler, and using a SAAJ Client, both does work.
我尝试的其他方法是 - 添加 JAX-WS 客户端处理程序,并使用 SAAJ 客户端,两者都有效。

