我有一个运行良好的 Web 服务的 Metro 客户端。但是,我们在实验室环境中无法访问该服务,因此我编写了一个模拟服务进行测试。我在理解端点以及如何设置它们时遇到问题。
我将 URL 传递给客户端构造函数并将其设置在请求上下文中,如下所示:
// Set the service port URL
BindingProvider bindingProvider = ((BindingProvider) port);
Map<String, Object> context = bindingProvider.getRequestContext();
context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
对于我的模拟服务,当我单击应用程序列表 (http://myserver:80/MySoapService) 中的“启动”链接时,我使用的是 Glassfish 给我的战争 URL。
代码是从提供给我们的 wsdl 生成的。WebService 界面如下所示:
@WebService(name = "My_Soap_Service", targetNamespace = "urn:My.DataEntityModel")
@XmlSeeAlso({
ObjectFactory.class
})
public interface MySoapService {
@WebMethod(operationName = "Ping", action = "urn:My.DataEntityModel/Ping")
@WebResult(name = "PingResult", targetNamespace = "urn:My.DataEntityModel")
@RequestWrapper(localName = "Ping", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.Ping")
@ResponseWrapper(localName = "PingResponse", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.PingResponse")
public String ping(
@WebParam(name = "inputString", targetNamespace = "urn:My.DataEntityModel")
String inputString);
@WebMethod(operationName = "ProcessRecordResult", action = "urn:My.DataEntityModel/ProcessRecordResult")
@WebResult(name = "ProcessRecordResultResult", targetNamespace = "urn:My.DataEntityModel")
@RequestWrapper(localName = "ProcessRecordResult", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessRecordResult")
@ResponseWrapper(localName = "ProcessRecordResultResponse", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessRecordResultResponse")
public String ProcessRecordResult(
@WebParam(name = "recordStatusXML", targetNamespace = "urn:My.DataEntityModel")
String recordStatusXML);
@WebMethod(operationName = "ProcessBatchResult", action = "urn:My.DataEntityModel/ProcessBatchResult")
@WebResult(name = "ProcessBatchResultResult", targetNamespace = "urn:My.DataEntityModel")
@RequestWrapper(localName = "ProcessBatchResult", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessBatchResult")
@ResponseWrapper(localName = "ProcessBatchResultResponse", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessBatchResultResponse")
public String processBatchResult(
@WebParam(name = "batchStatusXML", targetNamespace = "urn:My.DataEntityModel")
String batchStatusXML);
}
我的 web.xml 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class>
</listener>
<servlet>
<servlet-name>MySoapService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MySoapService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
我在设置 sun-jaxws.xml 文件时遇到问题。最初它看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint
name="MyService"
implementation="my.package.MySoapServiceImpl"
url-pattern="/"
wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/>
</endpoints>
但是我的客户返回了一个描述该服务的“Web 服务”HTML 页面。我无法找到 sun-jaxws.xml 文件的任何实用信息/示例,但我认为我需要为 web 服务中的每个方法提供一个端点。所以我把它改成这样:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint
name="Ping"
implementation="my.package.MySoapServiceImpl"
url-pattern="/ping"
wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/>
<endpoint
name="ProcessRecord"
implementation="my.package.MySoapServiceImpl"
url-pattern="/processRecordResult"
wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/>
<endpoint
name="ProcessBatch"
implementation="my.package.MySoapServiceImpl"
url-pattern="/processBatchResult"
wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/>
</endpoints>
现在,当我的客户端尝试访问该服务时,我收到 404 错误。
我不知道我是否错误地设置了 sun-jaxws.xml 和/或 web.xml 文件,在客户端使用了错误的 URL 或完全不同的东西。
有人可以告诉我我做错了什么和/或将我指向一个以易于理解的方式解释这一点的资源吗?