我可以在调用端点之前了解端点支持哪些 WCF 方法吗?
我遇到 WCF 服务合约的版本控制问题,其中为操作调用的众多端点之一缺少合约中的一种方法。
我的问题是,在尝试调用该命令之前,如何确保该命令在客户端上可用?
我尝试过:
foreach (var od in proxy.Endpoint.Contract.Operations)
{
if (od.Name == "MyMethodName")
{
hasMethod = true;
break;
}
}
不幸的是,这是使用调用应用程序的合同,并且实际上并没有描述端点本身的实现。因此,即使端点未能执行该命令,它也会返回 true。
I have a versioning issue with a WCF service contract in which one of the many endpoints which are called for the operation is missing one method from the contract.
My question is, how can I make sure the command is available on the client before attempting to call it?
I tried:
foreach (var od in proxy.Endpoint.Contract.Operations)
{
if (od.Name == "MyMethodName")
{
hasMethod = true;
break;
}
}
Unfortunately, this is using the contract from the calling app and does not actually describe the implementations on the endpoint itself. As a result, it returns true even though the endpoint has failed to implement the command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你尝试之前你永远不会真正知道。您拥有的是已实施合约的代理,但服务器端的内容可能会在您创建/生成它后发生变化。
假设它是一个 http/httpws 实现,我想您可以调用并检查服务引用并下载 wsdl 文件。这将告诉您支持哪些方法等。您将遇到的问题是,即使方法的名称可能相同,您也必须检查返回类型和参数,以真正确保它是相同的方法并且您可以使用您当前拥有的代理。
以下是有关 WCF 版本控制的链接:
http://msdn.microsoft.com/en-us/library/ms731060。 aspx
以下是有关 WCF 版本控制最佳实践的链接:
使用 WCF 对服务进行版本控制的最佳实践?
You'll never actually know until you try it. What you have is a proxy of the implemented contract, but what is on the server side could have changed since you created/generated it.
Assuming it's an http/httpws implementation I suppose you could call and check the service reference and download the wsdl file. That will tell you what methods etc are supported. The problem you're going to have is that even though the name of the method maybe the same, you'll also have to check the return type and parameters to really be sure that it's the same method and that you can call it with the proxy you currently have.
Here is a link on versioning in WCF:
http://msdn.microsoft.com/en-us/library/ms731060.aspx
Here is a link on versioning best practices for WCF:
Best practices for versioning your services with WCF?