我现在明白了。当您查看代码示例时,这是有道理的。以下是从 JBoss Admin 指南中提取的 StatefulEndpoint WebService 示例:
@WebService(name = "StatefulEndpoint", targetNamespace = "http://org.jboss.ws/sam ples/wsaddressing", serviceName = "TestService")
@Addressing(enabled=true, required=true)
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class StatefulEndpoint implements StatefulEndpoint, ServiceLifecycle
{
@WebMethod
public void addItem (String item )
{ ... }
@WebMethod
public String getItemsInCart()
{ ... }
}
然后 Web 服务客户端创建两个单独的端口
port1 = (StatefulEndpoint)service.getPort(StatefulEndpoint.class, new
javax.xml.ws.soap.AddressingFeature());
port2 = (StatefulEndpoint)service.getPort(StatefulEndpoint.class, new
javax.xml.ws.soap.AddressingFeature());
将新的 AddressingFeature 传入 getPort 函数将启用 WS 寻址功能。
这是演示我们刚刚创建的两个端口的状态的代码:
public class AddressingStatefulTestCase extends JBossWSTest
{
...
public void testAddItem() throws Exception
{
port1.addItem ("Ice Cream ");
port1.addItem ("Ferrari");
port2.addItem ("Mars Bar");
port2.addItem ("Porsche");
}
public void testGetItems() throws Exception
{
String items1 = port1.getItems();
assertEquals("[Ice Cream , Ferrari]", item s1);
String items2 = port2.getItems();
assertEquals("[Mars Bar, Porsche]", item s2);
}
}
请注意,port1 添加的项目与 port2 不同,但是当 port1 调用 getItems... 时,它只获取它添加的项目,而不是来自 port2 的项目。这就是赋予它状态的原因。