4
votes

I have generated classes for soap client using wsimport.exe.

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

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.

2

2 Answers

1
votes

I could not find a better solution than this using JAX-WS.

You can send any header using this approach.

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.

Info sysInfoOne = siOne.doGetSystemInfo(YourParam); becomes

Info sysInfoOne = siOne.doGetSystemInfo(YourParam, YourAnyTypeOfHeader); Reference - JAXWS Specification.

And this is what Developers like to do, rather than editing/sending the XML.

Other Approaches I tried were - adding a JAX-WS Client Handler, and using a SAAJ Client, both does work.

0
votes

Actually after more search through stackoverflow I found solution to my problem How do I add a SOAP Header using Java JAX-WS