I have a WSDL that it has username and password. I used to soapUI and created this WSDL classes, after that in soapUI, by right click on my project I created jax-ws artifacts in a folder in my computer, Then in eclipse I created a dynamic web project and added WSDL client files in my dynamic web project.
After that I wanted to used this wed-service so in a main-class I add these codes for getting output:
package ir.post.service.main;
import ir.post.service.Exception_Exception;
import ir.post.service.PostcodeWS;
import ir.post.service.PostcodeWSPortBindingQSService;
import javax.xml.ws.BindingProvider;
public class Demo {
public static void main(String[] args) throws Exception_Exception {
PostcodeWSPortBindingQSService service = new PostcodeWSPortBindingQSService();
PostcodeWS port = (PostcodeWS) service.getPort(PostcodeWSPortBindingQSService.class);
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "wsdlUsername");
provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "H!Tb3@hf");
System.out.println(port.getPostcodeByTelephone("webmethodUsername", "1300@$#0t$rn1n1s3@", 0221, 123456789));
}
}
After running above class as java application, I get this error :
Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://ip-address/post/PostcodeWSService?wsdl. It failed with:
Got Server returned HTTP response code: 401 for URL: http://ip-address/post/PostcodeWSService?wsdl while opening stream from http://ip-address/post/PostcodeWSService?wsdl.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at javax.xml.ws.Service.create(Unknown Source)
at ir.post.service.Demo.main(Demo.java:35)
Caused by: java.io.IOException: Got Server returned HTTP response code: 401 for URL: http://ip-address/post/PostcodeWSService?wsdl while opening stream from http://ip-address/post/PostcodeWSService?wsdl
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(Unknown Source)
... 9 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://ip-address/post/PostcodeWSService?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
... 11 more
How can I solve this issue? please help me about this problem?
Thanks.