获得合同

发布于 2024-08-27 12:38:54 字数 293 浏览 6 评论 0原文

有没有办法以编程方式从正在运行的服务获取合同?我想将正在运行的服务的合同与客户端引用的合同进行比较。

例如,我有两个 Service1 实例运行在具有不同实现的不同计算机上。 他们都有一个名为 IService1 的合约,但实现不同。 我有一个 Console1,它引用了 IService1(第一个实例)。 Console1有2个端点地址的集合。 Console1 想要检查哪个正在运行的服务对于他正在使用的合约(第一个实例)来说是正确的服务。

我在这里想要做的是使用地址以编程方式从服务获取合同,并将其与我拥有的引用合同进行比较。

Is there a way to get a contract from a running service programatically? I want to compare the contract of a running service from a referenced contract in the client side.

For example I have two instances of Service1 running on different machines that has different implementations.
They both have a contract named IService1 but different implementation.
I have a Console1 that has a reference to IService1(First instance).
Console1 has a collection of 2 endpoint address.
Console1 wants to check which of the running services is the correct service for the contract(First instance) he is using.

What I want to do here is to programatically get the contract from the service using the address and compare it to the referenced contract that I have.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2024-09-03 12:38:54

如果服务公开元数据,则可能是的。具体如何取决于所使用的绑定,如果是普通的 http 绑定,您可以使用 http://myserver/myservice。 svc?WSDL。要比较合约,您必须使用普通的 http API 下载 WSDL,然后将其与存储的参考 WSDL 进行比较。

我认为在实施比较之前还应该考虑一些事情:

  • 如果合同不匹配,WCF 将抛出错误。
  • 在某个命名空间中发布的某个合约不应该存在于不同的版本中。这更多的是一个常规问题,而不是一个技术问题。在像您这样的情况下,相同的合同由不同的服务实施,需要一个良好的合同变更例程。

If the service exposes metadata it is possible yes. Exactly how depends on the binding used, if it is a normal http binding you can use http://myserver/myservice.svc?WSDL. To compare the contracts you would have to download the WSDL by using a normal http API and then compare it to a stored reference WSDL.

There are also a few things I think you should take into consideration before implementing a comparison:

  • If the contracts doesn't match, WCF will throw errors.
  • A certain contract, published in a certain namespace should not exist in different versions. This is more of a routine issue than a technical issue. In cases such as yours where the same contract is implemented by different services a good routine for contract changes is needed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文