com.sun.xml.ws.fault.ServerSOAPFaultException:客户端从服务器收到SOAP Fault:未找到WS-Security标头

时间:2014-12-24 08:10:12

标签: java web-services ssl soap jax-ws

我在一个使用remote server over SSL上的网络服务的网络服务客户端上学习。    首先,我是Web服务的新手,我创建了基本的Web服务,然后才能在localhost上工作。这是一项复杂的业务,我需要帮助

WSDL file,KeyStore fileTrustStore file已发给我。我使用可以访问Web服务端点的计算机     我为此Web服务创建所做的工作;

  • 我使用wsimport tool
  • 中的wsdl file生成了java类
  • 然后我创建了一个Dynamic Web Project in Eclipse并导入了这些java类
  • 我将keystore,truststore and wsdl files复制到项目目录
  • 在课堂上'主要方法我写下面的代码。

    我在运行时在调用Web服务方法

    的代码行中得到以下异常
    com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: No WS-     Security header found exception
    

    我尝试访问以下网络服务的代码:

代码

        My_Service service=new My_Service();
        MyServicePort servicePort=service.getServicePort();

        BindingProvider bp = (BindingProvider)servicePort;

        // In case of 1-Way SSL, only the Truststore is necessary
        TrustManagerFactory tmf= TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init((KeyStore)null);
        TrustManager[] trustMgr= tmf.getTrustManagers();
        KeyStore trustStore = KeyStore.getInstance("JKS");
        FileInputStream truststoreFile = new FileInputStream("truststore.jks");
        trustStore.load(truststoreFile, "truststore_password".toCharArray());
        truststoreFile.close();
        tmf.init(trustStore);

        // In case of 2-Way SSL, keystore and  truststore are necessary
        KeyManagerFactory kmf= KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init((KeyStore)null,null);
        KeyManager[] keyMgr = kmf.getKeyManagers();
        KeyStore keyStore = KeyStore.getInstance("JKS");
        FileInputStream keystoreFile = new FileInputStream("keystore.jks");
        keyStore.load(keystoreFile, "keystore_password".toCharArray()); 
                keystoreFile.close();
        kmf.init(keyStore, "keystore_password".toCharArray());

        SSLContext context = SSLContext.getInstance("SSL");//"SSLv3"
        context.init(keyMgr, trustMgr, null);
        //context.getSocketFactory();
        bp.getRequestContext().put(JAXWSProperties.SSL_SOCKET_FACTORY, context.getSocketFactory());
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"username");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"password");
                bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://xxxxxxx....");

**ERROR IN THIS LINE** //List<MyEntity> list= servicePort.getEntityList();
        for(MyEntity e:list){
            System.out.println(e.getName());
        }

如何解决问题?此外,任何有关创建此类Web服务客户端的建议都会受到赞赏。  提前致谢

0 个答案:

没有答案