我有一个模型,用于在服务器上创建 Web 服务端点。客户端使用相同的模型。但是,当向服务器添加新操作但客户端仍使用旧模型时,服务创建会失败,并出现如下异常(为了清楚起见,添加了换行符):
Exception in thread "main" javax.xml.ws.WebServiceException:
Method someNewMethod is exposed as WebMethod, but there is no
corresponding wsdl operation with name someNewMethod in the
wsdl:portType{http://example.com}MyService
Run Code Online (Sandbox Code Playgroud)
我理解这个问题,但是可以忽略它吗?我希望在使用 Web 服务时能够向后兼容。只要添加方法,大多数时候就应该可以正常工作。
问题出现在getPort方法中:
Service s = Service.create(
new URL("http://example.com/foo?wsdl"),
new QName("http://example.com", "MyService"));
MyService m = s.getPort(MyService.class);
Run Code Online (Sandbox Code Playgroud)
使用本地 WSDL 文件:
客户端应用程序有一个服务的本地 WSDL 文件,例如在 jar 文件内。
你得到它
URL wsdlURL = this.getClass().getClassLoader()
.getResource("MyWebService.wsdl");
Run Code Online (Sandbox Code Playgroud)
这适用于我编写的应用程序。服务器后来扩展了附加的 WSDL 属性,而客户端仍然使用本地属性。