我正在尝试使用SSL/HTTPS
开发安全的网络服务。所以我创建了服务器&客户端密钥库文件按(link)和低于服务器&客户端代码,但客户端代码被抛出异常:
com.sun.xml.ws.model.RuntimeModelerException: A WebService annotation is not present on class: com.heb.service.WpcimService
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1604)
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1597)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:413)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:433)
at javax.xml.ws.Service.getPort(Unknown Source)
at com.heb.client.WpcimClient.main(WpcimClient.java:32)
服务器代码:
public class SampleWebService {
public String method(String plainNumericCCNum)
{
return value;
}
客户代码:
import java.net.URL;
import javax.xml.ws.Service;
import javax.xml.namespace.QName;
public class WebServiceClient {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Wpcim Client");
try
{
System.setProperty("javax.net.ssl.trustStore","d:/client.keystore");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");
URL url = new URL("https://localhost:8443/Mywebservice/services/SampleWebService?wsdl");
QName qname = new QName("http://service.client.com", "SampleWebService");
Service service = Service.create(url, qname);
SampleWebService hello = service.getPort(SampleWebService.class);
System.out.println(hello.method("1234"));
}catch(Exception ex){
ex.printStackTrace();
}
}
}
请帮我查一下,可能是什么问题? 提前谢谢。
答案 0 :(得分:0)
在您的服务器代码中,您需要添加@WebService
注释。即你的代码应该是
@WebService(
portName = "Port name here",
serviceName = "Service name here",
targetNamespace = "your tns here")
public class SampleWebService {
public String method(String plainNumericCCNum)
{
return value;
}
}