C# WCF 向后兼容性问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Backward Compatibility Issue
提问by lomaxx
I have a WCF service that I have to reference from a .net 2.0 project.
我有一个 WCF 服务,我必须从 .net 2.0 项目中引用它。
I have tried to reference it using the "add web reference" method but it messes up the params.
我尝试使用“添加网络引用”方法来引用它,但它弄乱了参数。
For example, I have a method in the service that expects a char[]
to be passed in, but when I add the web reference, the method expects an int[]
.
例如,我在服务中有一个方法char[]
需要传入a ,但是当我添加 Web 引用时,该方法需要传入int[]
.
So then I tried to setup svcutiland it worked... kind of.
I could only get the service class to compile by adding a bunch of .net 3.0references to my .net 2.0project. This didn't sit well with the architect so I've had to can it (and probably for the best too).
然后我尝试设置svcutil并且它起作用了......有点。
我只能通过向我的.net 2.0项目添加一堆.net 3.0引用来编译服务类。这对建筑师来说并不合适,所以我不得不这样做(并且可能也是最好的)。
So I was wondering if anyone has any pointers or resources on how I can setup a .net 2.0project to reference a WCF service.
所以我想知道是否有人有任何关于如何设置.net 2.0项目以引用WCF 服务的指针或资源。
采纳答案by lomaxx
One of those instances that you need to edit the WSDL. For a start a useful tool
您需要编辑 WSDL 的那些实例之一。首先是一个有用的工具
回答by lomaxx
Thanks for the resource. It certainly helped me test out the webservice, but it didn't much help with using the WCF service in my .net 2.0 application.
谢谢你的资源。它确实帮助我测试了 web 服务,但是在我的 .net 2.0 应用程序中使用 WCF 服务并没有太大帮助。
What I eventually ended up doing was going back to the architects and explaining that the 3.0 dll's that I needed to reference got compiled back to run on the 2.0 CLR. We don't necessarily like the solution, but we're going to go with it for now as there doesn't seem to be too many viable alternatives
我最终做的是回到架构师那里并解释说我需要引用的 3.0 dll 被编译回以在 2.0 CLR 上运行。我们不一定喜欢该解决方案,但我们现在将采用它,因为似乎没有太多可行的替代方案
回答by lomaxx
What binding are you using - I think if you stick to the basicHttp binding you should be able to generate a proxy using the "add web reference" approach from a .net 2 project?
您使用的是什么绑定 - 我认为如果您坚持使用 basicHttp 绑定,您应该能够使用 .net 2 项目中的“添加 Web 引用”方法生成代理?
Perhaps if you post the contract/interface definition it might help?
也许如果您发布合同/接口定义可能会有所帮助?
Cheers Richard
干杯理查德
回答by lomaxx
I was using the basicHttp binding but the problem was actually with the XMLSerializer. It doesn't properly recognize the wsdl generated by WCF (even with basicHttp bindings) for anything other than basic value types.
我使用的是 basicHttp 绑定,但问题实际上出在 XMLSerializer 上。它不能正确识别 WCF 生成的 wsdl(即使使用 basicHttp 绑定),用于除基本值类型之外的任何内容。
We got around this by added the reference to the 3.0 dll's and using the datacontract serializer.
我们通过添加对 3.0 dll 的引用并使用数据契约序列化程序来解决这个问题。