WCF 以编程方式设置端点地址:在配置元素集合中找不到与键匹配的元素

发布于 2024-12-19 07:06:34 字数 1249 浏览 1 评论 0原文

我正在执行我认为是一项非常基本的任务。我们有一个包含多个服务器(开发、测试、生产)的环境,我想以编程方式更改服务端点。为此,我创建一个新的 EndPointAddress 并将客户端实例化为:

BasicHttpBinding binding = new BasicHttpBinding("BasicHttpBinding_IMyService");
EndpointAddress endpoint = new EndpointAddress(new Uri("http://domain.name/myservice.svc"));
MyService.MyServiceClient client = new MyService.MyServiceClient(binding, endpoint);

我收到以下错误。

在配置元素集合中找不到与键“BasicHttpBinding_IMyService”匹配的元素。

我已在下面包含了我的 app.config,但如您所见,我确实定义了绑定。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IMyService" >
               <... removed directives for ease of reading ...>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://domain.name/MyService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
            contract="MyService.IMyService" name="BasicHttpBinding_IMyService" />
    </client>
</system.serviceModel>

如果这是一个简单的问题,我很抱歉,但我无法找出问题所在。我将其称为“周五晚些时候的脑雾”,也许你可以将其称为“简单点”?

谢谢!

I'm performing what I believed was a pretty basic task. We have an environment with multiple servers (DEV, TEST, PRODUCTION) and I'd like to programmatically change the service endpoint. To do this I am creating a new EndPointAddress and instantiating the client as:

BasicHttpBinding binding = new BasicHttpBinding("BasicHttpBinding_IMyService");
EndpointAddress endpoint = new EndpointAddress(new Uri("http://domain.name/myservice.svc"));
MyService.MyServiceClient client = new MyService.MyServiceClient(binding, endpoint);

I am receiving the following error.

No elements matching the key 'BasicHttpBinding_IMyService' were found in the configuration element collection.

I have included my app.config below but, as you can see, I do have the binding defined.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IMyService" >
               <... removed directives for ease of reading ...>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://domain.name/MyService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
            contract="MyService.IMyService" name="BasicHttpBinding_IMyService" />
    </client>
</system.serviceModel>

I'm sorry if this is a simple question but I haven't been able to identify the problem. I'll call it the 'late-Friday brain fog', and maybe you can call it 'easy points'?

Thanks!

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

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

发布评论

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

评论(1

錯遇了你 2024-12-26 07:06:34

WCF 应用程序的 Web.config 和客户端应用程序的 app.config 中的绑定必须匹配

The bindings in the Web.config of the WCF application and the app.config of the client application must match

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文