我有一个Metro客户端到Web服务工作正常。但是,我们在实验室环境中无法访问该服务,因此我编写了一个模拟服务进行测试。我在理解端点以及如何设置端点方面遇到了问题。
我将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。 / p>
代码是从提供给我们的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文件的任何实用信息/示例,但我认为我需要为webservice中的每个方法提供一个端点。所以我改变它看起来像这样:
<?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或完全不同的内容。
有人可以告诉我我做错了什么和/或指向一个以易于理解的方式解释这个问题的资源吗?
答案 0 :(得分:0)
我得到了它,如果这对其他人有用,这是我的配置......
<强>的web.xml 强>
<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>/service</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
<强>太阳jaxws.xml 强>
尽管我发现许多示例/博客都声明sun-jaxws.xml文件中的port
和service
元素是可选的,但如果没有它们,我无法让它工作。另外,我发现如果在Glassfish上部署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"
interface="my.package.MySoapServiceInterface"
implementation="my.package.MySoapServiceImpl"
service="{urn:my.xmlns.tns.urn}My_Soap_Service"
port="{urn:my.xmlns.tns.urn}My_Port_Type"
url-pattern="/service"
wsdl="WEB-INF/wsdl/MyService.wsdl"
</endpoints>
Web Service Impl Class
我发现有必要在WebSevice注释中包含endpointInterface
:
@WebService(endpointInterface="my.package.MySoapServiceInterface")
public class MySoapServiceImpl implements MySoapServiceInterface
当然,每个Web服务方法都需要使用WebMethod
注释:
@WebMethod
public String doSomething(String string)