我正在做一个WCF - WSIT (Metro)集成项目,我想允许Java客户端连接到持久服务。
持久服务http://msdn.microsoft.com/en-us/library/bb410767(v=vs.90).aspx
持久服务需要wsHttpContextBinding,它似乎工作得很好。唯一的问题是WSIT客户端生成的代理似乎不能将instanceId分配给soap信封。有没有我不知道的配置设置,或者是截获传出消息并附加instanceId的方法?
下面的SOAP示例由.NET客户端生成。信封WSIT send和这个之间的唯一区别是WSIT中缺少上下文节点:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
...
<Context xmlns="http://schemas.microsoft.com/ws/2006/05/context">
<Property name="instanceId">{I want to set this Id}</Property>
</Context>
...
</s:Header>
<s:Body>
<IncreaseCounter xmlns="http://tempuri.org/"/>
</s:Body>
</s:Envelope>我希望这是有意义的。这个问题不是与ws2007HttpBinding或wsHttpBinding相关的,也不是与WCF实例管理相关的;per/call,session,single。我需要帮助与WSIT,Java位只。
发布于 2011-04-08 23:48:23
我的一位同事在该项目的Java端工作,他帮助我弄清楚了语法。我分享这个解决方案,因为它可能对其他人有用。这篇文章的意义在于,WSIT文档都没有提到持久的WCF服务可以与Java客户端一起使用。如果您需要编写一个java客户端,该客户端可以参与长时间运行的工作流或托管的Windows工作流(WF)的客户端,则持久性WCF是必不可少的。
下面的Java代码返回相关的头部:
private static Header getContextHeader(IDemoService port) {
Header contextHeader = null;
Iterator<Header> iterator = ((WSBindingProvider)port).getInboundHeaders().iterator();
while(iterator. hasNext()){
Header header = iterator.next();
if (header.getLocalPart().equalsIgnoreCase("Context")) {
contextHeader = header;
}
}
return contextHeader;
}然后您可以像这样设置上下文:
Header contextHeader = getContextHeader(port);
((WSBindingProvider)port).setOutboundHeaders(contextHeader); 发布于 2011-03-25 00:45:59
您可能需要指定wcf服务的实例管理,有3个选项:
看起来你需要每一次会话。
http://www.dotnetfunda.com/articles/article912-3-ways-to-do-wcf-instance-management-per-call-per-session-and-single-.aspx
https://stackoverflow.com/questions/5420090
复制相似问题