WCF 服务 - 向后兼容性问题
我刚刚开始创建一些 WCF 服务,但我需要使它们向后兼容旧版(.NET 1.1 和 2.0)客户端应用程序。
我已经设法让服务在 3.0 及更高版本的客户端上正确运行,但是当我使用 basicHttpBinding 端点(我相信这是我所需的兼容性所必需的)发布服务时,该服务会重构我的方法签名。 例如,
public bool MethodToReturnTrue(string seedValue);
在客户端应用程序中,
public void MethodToReturnTrue(string seedValue, out bool result, out bool MethodToReturnTrueResultSpecified);
我已经尝试了我在自托管控制台应用程序的 app.config 中能想到的所有配置参数,但我似乎无法按预期实现此功能。 我想这可能会导致我的期望有缺陷,但令我惊讶的是 WCF 服务无法处理向下级客户端的 bool 返回类型。
我当前的 app.config 看起来像这样。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" Name="MyCompany.Services.CentreService.CentreService">
<clear />
<endpoint address="http://localhost:8080/CSMEX" binding="basicHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="http://localhost:8080/CentreService" binding="basicHttpBinding" bindingName="Compatible" name="basicEndpoint" contract="MyCompany.Services.CentreService.ICentreService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
有人可以建议吗?
I'm just getting into creating some WCF services, but I have a requirement to make them backward compatible for legacy (.NET 1.1 and 2.0) client applications.
I've managed to get the services to run correctly for 3.0 and greater clients, but when I publish the services using a basicHttpBinding endpoint (which I believe is required for the compatibility I need), the service refactors my method signatures. e.g.
public bool MethodToReturnTrue(string seedValue);
appears to the client apps as
public void MethodToReturnTrue(string seedValue, out bool result, out bool MethodToReturnTrueResultSpecified);
I've tried every configuration parameter I can think of in the app.config for my self-hosting console app, but I can't seem to make this function as expected. I suppose this might lead to the fact that my expectations are flawed, but I'd be surprised that a WCF service is incapable of handling a bool return type to a down-level client.
My current app.config looks like this.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" Name="MyCompany.Services.CentreService.CentreService">
<clear />
<endpoint address="http://localhost:8080/CSMEX" binding="basicHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="http://localhost:8080/CentreService" binding="basicHttpBinding" bindingName="Compatible" name="basicEndpoint" contract="MyCompany.Services.CentreService.ICentreService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Can anyone advise, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须使用 XmlSerializer。 例如:
您必须手动设置操作操作名称,因为自动生成的 WCF 名称的构造与 ASMX 操作名称不同(WCF 也包括接口名称,ASMX 不包括)。
您使用的任何数据协定都应该用
[XmlType]
修饰,而不是[DataContract]
。您的配置文件不需要更改。
You do have to use the XmlSerializer. For example:
You have to manually set the operation action name because the auto-generated WCF name is constructed differently from the ASMX action name (WCF includes the interface name as well, ASMX does not).
Any data contracts you use should be decorated with
[XmlType]
rather than[DataContract]
.Your config file should not need to change.
好的,我们需要在短期内解决这个问题,因此我们提出了“互操作”或兼容性层的想法。
基本上,我们所做的就是向项目添加传统的 ASMX Web 服务,并使用本机 WCF 调用从中调用 WCF 服务。 然后,我们能够将适当的类型返回给客户端应用程序,而无需进行大量的重构工作。 我知道这是一个很糟糕的解决方案,但它是我们对如此庞大的遗留代码库的最佳选择。 额外的好处是它实际上效果出奇的好。 :)
OK, we needed to resolve this issue in the short term, and so we came up with the idea of a "interop", or compatibility layer.
Baiscally, all we did was added a traditional ASMX web service to the project, and called the WCF service from that using native WCF calls. We were then able to return the appropriate types back to the client applications without a significant amount of re-factoring work. I know it was a hacky solution, but it was the best option we had with such a large legacy code-base. And the added bonus is that it actually works surprisingly well. :)
啊,这真是要了我的命啊! 大约三个月前我在工作中做了这件事,现在我不记得所有细节了。
但是,我确实记得您需要 basicHttpBinding,并且不能使用新的序列化程序(这是默认设置); 您必须使用“旧”XmlSerializer。
不幸的是,我不再在我做这件事的地方工作了,所以我不能去看代码。 我会打电话给我的老板,看看我能挖到什么。
Ah, this is killing me! I did this at work about 3 months ago, and now I can't remember all the details.
I do remember, however, that you need basicHttpBinding, and you can't use the new serializer (which is the default); you have to use the "old" XmlSerializer.
Unfortunately, I don't work at the place where I did this anymore, so I can't go look at the code. I'll call my boss and see what I can dig up.