我有一个用@WebService(serviceName="MyServiceName", portName="MyPortName")
注释的EJB3 session bean。将其部署到Weblogic 11g中时,服务端点位于host:port/BeanClassName/MyServiceName
是否可以更改Web服务的服务端点地址?即host:port/my/context/root/something/MyServiceName
我尝试使用weblogic-webservices.xml部署描述符,但它需要webservices.xml描述符,该描述符需要WSDL位置元素,但该位置元素应由服务器生成,并且其位置在开发和生产环境中有所不同。
最佳答案
假设您有一个EJB
package com.example;
@Stateless
@WebService
OrganizationService {...}
首先,您应该为它编写一个webservices.xml文件,如下所示,因为将从完成实际端点配置的weblogic-webservices.xml中引用它的各个部分。
webservices.xml(警告:通过在类中添加webservices.xml webservice批注会被覆盖!):
<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
<webservice-description>
<!-- just a label, can be anything you want -->
<webservice-description-name>MyServiceName</webservice-description-name>
<port-component>
<!-- just a label, can be anything you want -->
<port-component-name>MyServicePort</port-component-name>
<!-- Target namespace from wsdl -->
<wsdl-port xmlns:ex="http://example.com/target/name/Space">ex:MyService</wsdl-port>
<!-- Fully qualified class name of the ejb interface/bean providing the service -->
<service-endpoint-interface>com.example.OrganizationService</service-endpoint-interface>
<service-impl-bean>
<!-- The class name of the bean providing the service -->
<ejb-link>OrganizationService</ejb-link>
</service-impl-bean>
</port-component>
</webservice-description>
</webservices>
然后,可以在weblogic-webservices.xml中定义所需的任何端点。
weblogic-webservices.xml:
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-webservices xmlns="http://www.bea.com/ns/weblogic/weblogic-webservices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-webservices http://www.bea.com/ns/weblogic/weblogic-webservices/1.0/weblogic-webservices.xsd">
<webservice-description>
<!-- This must match the name given in webservices.xml -->
<webservice-description-name>MyServiceName</webservice-description-name>
<webservice-type>JAXWS</webservice-type>
<port-component>
<!-- This must match the name given in webservices.xml -->
<port-component-name>MyServicePort</port-component-name>
<service-endpoint-address>
<webservice-contextpath>/myContextPath</webservice-contextpath>
<webservice-serviceuri>/myServiceURI</webservice-serviceuri>
</service-endpoint-address>
</port-component>
</webservice-description>
</weblogic-webservices>