【问题标题】:How to dynamically select the URI for a WCF service?如何动态选择 WCF 服务的 URI?
【发布时间】:2009-04-01 23:05:09
【问题描述】:

我正在尝试使用运行时 URI 字符串构造 WCF 客户端对象。这似乎很简单,但我已经没有办法尝试似乎“错误的方法”了。

原代码是这样的:

IPrototype p =  new prototype.PrototypeClient();

我有点期待它能够像这样工作。

string uri = GetMeMyURI();
IPrototype p =  new prototype.PrototypeClient(new URI(uri));

【问题讨论】:

    标签: c# .net wcf uri


    【解决方案1】:

    在不知道您的 PrototypeClient 类是什么的情况下很难判断出了什么问题,它是 WCF 代理吗?

    以编程方式设置 WCF 客户端的基本机制是:

    BasicHttpBinding binding = new BasicHttpBinding();
    EndpointAddress address = new EndpointAddress(GetMeMyURI());
    PrototypeClient yourProxy = new PrototypeClient(binding, address);
    

    编辑:

    为了避免必须知道服务器绑定:

    PrototypeClient yourProxy = new PrototypeClient();
    yourProxy.Endpoint.Address = new EndpointAddress(GetMeMyURI(), null);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多