开发者

Getting the contract

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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜