2

I am attempting to call a webservice (developed in C#) using JAX-WS, over https. I have tried setting up an invocation through SoapUI, and this works.

But, when trying to do the same through a generated jax-ws client, all I get is a 301 response back. This is similar to what I get using SoapUI with a http url to the same service, and also wireshark tells me that I do a HTTP (HTTP/XML) POST operation. This leads me to belive that for some reason, my generated JAX-WS client attempts to invoke over http, instead of https.

Examplified code:

 new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl"))
                       .getMyPort().test();

As you can see, I supply a https url when creating my client. Is there anything else needed in order to make sure that JAX-WS uses https? The namespace URIs are all http, could this cause problems?

Update:

I have implemented a SOAP-request for the service in quesiton using the guide from the accepted answer here: Working Soap client example Pretty much repeated the information from SoapUI, and now it gives me the a proper 200 response.

Update 2:

When debugging my JAX-WS-client, I find this property:

"javax.xml.ws.service.endpoint.address" -> "http://acme.com/services/MyService.svc"

This has http, not https. Relevant?

Update 3:

When using the debugger to change "javax.xml.ws.service.endpoint.address" to the https url, rather than http, my client works. But why is it http to begin with?

Community
  • 1
  • 1
Tobb
  • 11,850
  • 6
  • 52
  • 77

1 Answers1

8

One cause could be if the WSDL referenced an http URL.

new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl")) .getMyPort().test();

I'd suggest downloading https://acme.com/services/MyService.svc?wsdl and looking at the <address> or endpoint within the <service>. If it looks like this:

<soap:address location="http://acme.com/services/MyService.svc"/>

That could account for what you are seeing in the javax.xml.ws.service.endpoint.address.

If that's the case and you cannot control/fix the remote WSDL, you may need to programmatically override the endpoint:

MyServicePort myPort = new MyServiceInterface(new URL("https://acme.com/services/MyService.svc?wsdl")).getMyPort();
// set endpoint to use https
String endpointURL = "https://acme.com/services/MyService.svc";
BindingProvider bp = (BindingProvider) myPort;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
myPort.test();
Scott Heaberlin
  • 3,364
  • 1
  • 23
  • 22
  • I'll check it out, and as a side-note I got it working by setting the property manually. Just to get to the next problem (of course), with jax-b generating xml with the wrong name. Meh, life as a developer :p – Tobb May 12 '16 at 07:11
  • Checked the WSDL, and you are correct, the address-element inside the service-element has a http URL. Could this be called a bug? Or is it just how things are done in .NET-created wsdls? – Tobb May 12 '16 at 07:13
  • you avoid me a lot of headhakes! I was trying to fix the issue with system administrators without success. I notice the http reference in the wsdl but I was not sure it had an impact on the client call (having set a different endpoint). I tried your solution that works perfectly ;) – OPMendeavor Aug 24 '18 at 14:41
  • That solved my issue, thanks! It's weird that a SOAP request in java can't handle redirects tough, it seems like a big limitation, and the workaround seems hackish, having to dynamically cast to `BindingProvider` (and if in a newer version it stops implementing that interface, I would receive no errors at compile time, only at runtime) without a method to handle that (in `MyServicePort`, a method like `setEndpoint` or anything like that). – Lucas Basquerotto Mar 29 '23 at 19:22