1

簡単な jax-ws Web サービスを作成し、正常にデプロイしました。次に、1 つのクライアント (jax-ws) を作成しましたが、実行中に次のエラーが表示されます。

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL  
at: file:./WEB-INF/wsdl/HelloService.wsdl. It failed with:.\WEB-INF\wsdl\HelloService.wsdl

しかし、同じ wsdl のクライアント (apache) を作成すると、動作します。助けてください。

これはクライアント ファイルです。 java.rmi.RemoteException をインポートします。

public class MainClass {

    public static void main(String[] args) throws RemoteException {

        HelloPortProxy obj = new HelloPortProxy();
        System.out.println(obj.sayhello("Everyone"));
        System.out.println("Count:"+obj.getCheckVal());

    }

}
4

1 に答える 1

3

それで、あなたには何がわかりませんか?例外:は、このパス内ではjavax.xml.ws.WebServiceException: Failed to access the WSDLWeb サービスにアクセスできないことを明確に示しています: 。WSDL/WEB-INF/wsdl/HelloService.wsdl

Web サービスを展開し、URL. 例: 次のようなクライアントをhttp://somehost/somepath/YourService?wsdl作成するよりも:JAX-WS

try {        
    final String username = "someusername";
    final String password = "somepassword";
    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(
                    username,
                    password.toCharArray());
        }
    });
    URL url = new URL("");
    QName qname = new QName("http://somehost/somepath/YourService?wsdl", "YourService");
    Service service = Service.create(url, qname);
    YourService proxy = service.getPort(YourService.class);
    Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());
    requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
} catch (Exception e) {
    //Handle Error.
}

将来必要になる可能性があるため、基本認証のコードも配置しました。現時点では、それを削除するだけです。

于 2013-02-07T13:27:58.337 に答える