管理同一服务的多个WCF端点

时间:2021-01-01 16:49:51

I am building an single application that uses WCF to call out to multiple external endpoints. All of the remote endpoints are identical except for the URI. I would like to treat them as a pool: add and remove endpoints through configuration and have the application understand what to do.

我正在构建一个应用程序,它使用WCF调用多个外部端点。除了URI之外,所有远程端点都是相同的。我希望将它们视为一个池:通过配置添加和删除端点,并让应用程序了解要做什么。

My original plan was to define one endoint in the app.config, then iterate over my list of endpoints and update client.Endpoint.Address on the fly to point to the right place. Unfortunately, that property is read-only, rendering that plan unworkable.

我最初的计划是在app.config中定义一个endoint,然后迭代我的端点列表并更新client.Endpoint。地址是动态的,指向正确的地方。不幸的是,该属性是只读的,这使得该计划不可用。

I'm a little bit stumped here. Any suggestions on how I might accomplish this?

我有点困惑。有什么建议吗?

3 个解决方案

#1


1  

How to: Create a Service Endpoint in Code shows you how to manage service endpoints in code rather than configuration.

如何:在代码中创建服务端点显示如何管理代码中的服务端点,而不是配置。

#2


0  

Have you tried a separate name that is passed in to the client constructor?

您是否尝试过将一个单独的名称传递给客户端构造函数?

          <endpoint address="http://localhost:18000/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="BasicHttpBinding_IMyService" />
          <endpoint address="http://localhost:18001/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="MyService_Secondary" />
          <endpoint address="http://localhost:18002/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="MyService_Tertiary" />

#3


0  

Store the end point addresses in a DB table and use Jason's suggestion for creating end points in code. When a new endpoint shows up you just add another row to the table and force the service to re-query the endpoint table.

将端点地址存储在DB表中,并使用Jason的建议在代码中创建端点。当出现新的端点时,只需向表添加另一行并强制服务重新查询端点表。

How to: Create a Service Endpoint in Code http://msdn.microsoft.com/en-us/library/ms731080.aspx

如何:在代码http://msdn.microsoft.com/en-us/library/ms731080.aspx中创建服务端点

#1


1  

How to: Create a Service Endpoint in Code shows you how to manage service endpoints in code rather than configuration.

如何:在代码中创建服务端点显示如何管理代码中的服务端点,而不是配置。

#2


0  

Have you tried a separate name that is passed in to the client constructor?

您是否尝试过将一个单独的名称传递给客户端构造函数?

          <endpoint address="http://localhost:18000/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="BasicHttpBinding_IMyService" />
          <endpoint address="http://localhost:18001/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="MyService_Secondary" />
          <endpoint address="http://localhost:18002/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyServiceReference.IMyService" name="MyService_Tertiary" />

#3


0  

Store the end point addresses in a DB table and use Jason's suggestion for creating end points in code. When a new endpoint shows up you just add another row to the table and force the service to re-query the endpoint table.

将端点地址存储在DB表中,并使用Jason的建议在代码中创建端点。当出现新的端点时,只需向表添加另一行并强制服务重新查询端点表。

How to: Create a Service Endpoint in Code http://msdn.microsoft.com/en-us/library/ms731080.aspx

如何:在代码http://msdn.microsoft.com/en-us/library/ms731080.aspx中创建服务端点