我在一个使用remote server over SSL
上的网络服务的网络服务客户端上学习。
首先,我是Web服务的新手,我创建了基本的Web服务,然后才能在localhost上工作。这是一项复杂的业务,我需要帮助
WSDL file,KeyStore file
和TrustStore 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服务客户端的建议都会受到赞赏。 提前致谢