2

I have a JAX-WS web service that is working fine when it gets called from any clients (i.e. Java destkop application) but not from JavaScript.

My WS interface looks like this:

@WebService
public interface LicenseService {

    @WebMethod
    String getLicense(
            @WebParam(name="coupon") String coupon,
            @WebParam(name="licenseCode") String licenseCode,
            @WebParam(name="secret") String secret);
    }

and I call it from javascript like this:

var request = new XMLHttpRequest();
request.open("POST", url, false);

request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
request.send(envelope);

and the sent envelope looks like this:

<?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>
        <getLicense xmlns="http://ws.licenseman.elevelcbt.eu/">
            <coupon>SYcj1J9I</coupon>
            <licenseCode>BEPRO</licenseCode>
            <secret>1234567890</secret>
        </getLicense>
    </soap:Body>
</soap:Envelope>

The method gets called (I can track on the Java side) but all passed parameters are null. There must be something wrong on my envelope format/contents.

DNA
  • 42,007
  • 12
  • 107
  • 146
lviggiani
  • 5,824
  • 12
  • 56
  • 89

1 Answers1

1

Ok I got it. I needed to change my envelope format to look like this (I got it by tracing the raw xml message when successfully calling the WS from java client):

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <ns1:getLicense xmlns:ns1="http://ws.licenseman.elevelcbt.eu/">
            <coupon>1111</coupon>
            <licenseCode>BEPRO</licenseCode>
            <secret>xxxxxxx</secret>
        </ns1:getLicense>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

It seems JAX-WS doesn't like method declaration like this:

<getLicense xmlns="http://ws.licenseman.elevelcbt.eu/">

and wants it like that:

<ns1:getLicense xmlns:ns1="http://ws.licenseman.elevelcbt.eu/">
lviggiani
  • 5,824
  • 12
  • 56
  • 89
  • Thanks for the help! After spending hours in this issue, I fixed the problem doing what you suggest. Except that I only added this "ns1" in the tags instead of change "soap:Envelope" by "SOAP-ENV:Envelope", for example, and make the other modifications. – José Augustinho Nov 12 '16 at 00:52
  • Thanks for this. I'm having the same issue. The C# clients are going completely crazy since they generate their requests like in your issue. – Markus Jul 26 '17 at 10:37