开发者

WCF Client configuration - base address?

开发者 https://www.devze.com 2022-12-15 20:21 出处:网络
I\'m connecting a WCF client to a group of services all implementing the same contract and all at the same host.I was hoping that there would be a way to combine the endpoint definitions to cut down o

I'm connecting a WCF client to a group of services all implementing the same contract and all at the same host. I was hoping that there would be a way to combine the endpoint definitions to cut down on configuration clutter. I also would rather not do it programmaticly - just by configur开发者_运维百科ation. Right now, my config has this repeated many times:

<endpoint address="http://hostname/ServiceA.svc"
         binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding"
         contract="ServiceReference.ISearchService" name="ServiceA">
</endpoint>

<endpoint address="http://hostname/ServiceB.svc"
         binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding"
         contract="ServiceReference.ISearchService" name="ServiceB">
</endpoint>

// continued for ServiceC, ServiceD, etc

For server configurations, there is some notion of "baseAddressPrefixFilters" that can be used for this purpose - is there anything for client configuration?


There is the concept of a base address in WCF - unfortunately, that only works if you self-host, e.g. host your service in a console app or NT service. However, that only works on the server side - there's nothing similar on the client side. On the client side, you always have to define the complete, full service address your endpoint should connect to.

If you host in IIS, your service address is determined by the server name, the virtual directory (and possibly subdirectories under that) and the name of the *.svc file used to host the service in IIS. This is a fixed system convention and you cannot influence it, unfortunately (.NET 4 will bring some remedy to that).

0

精彩评论

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