生成wsdl客户端文件为jax-ws格式后出错

时间:2015-12-23 12:01:56

标签: web-services wsdl jax-ws soapui

我有一个WSDL,它有用户名和密码。我曾经在 soapUI 创建了这个WSDL类,之后在soapUI中,右键单击我的项目,我在计算机的一个文件夹中创建了 jax-ws artifacts ,然后在eclipse我创建了一个动态Web项目,并在我的动态Web项目中添加了WSDL客户端文件。

enter image description here

之后我想使用这个结婚服务,所以在主类我添加这些代码以获得输出:

    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));    
    }   
}

在作为java应用程序运行上面的类之后,我收到此错误:

    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

我该如何解决这个问题? 请帮我解决这个问题?

感谢。

0 个答案:

没有答案