【问题标题】:Skipping App.config configuration and configuring in C#跳过 App.config 配置并在 C# 中进行配置
【发布时间】:2015-09-23 20:51:30
【问题描述】:

如果我想从我的 客户端 代码中删除 app.config 配置的必要性,并从我的 c# 初始化客户端。在我的 C# 代码中定义绑定和端点。以下客户端代码的 C# 版本是什么:

<client>
            <endpoint address="http://employeetstsvc/Employee.svc" binding="wsHttpBinding"
                bindingConfiguration="StandardEndpoint" contract="ServiceReference2.IHREmployee"
                name="StandardEndpoint" />
        </client>

有什么想法吗?

【问题讨论】:

    标签: c# web-services wcf soap config


    【解决方案1】:

    如下所示。查看更多Here

    String baseAddress = "http://employeetstsvc/Employee.svc";
    
    WSHttpBinding binding1 = new WSHttpBinding();
    
    using(ServiceHost host = new ServiceHost(typeof(Employee)))
    {
       host.AddServiceEndpoint(typeof(ServiceReference2.IHREmployee),binding1, baseAddress);
    }
    

    【讨论】:

    • 这实际上是客户端配置。似乎您建议的答案是服务器端。对不起,我应该更具体。我更新了我的问题,这样就不会有更多的困惑
    • @CoffeeBean,你不是说在我的C#代码中定义绑定和端点的c#初始化客户端吗?现在有点迷茫……
    • 我很抱歉造成混乱。我只是在编写客户端代码。 "http://employeetstsvc/Employee.svc" 已经存在。我想调用该服务,但我想跳过 app.config 配置并从 C# 代码初始化代理
    • @CoffeeBean,呃!!!您的意思是,不想使用服务引用直接从代码创建代理?
    • @CoffeeBean,你要找的就在这里stackoverflow.com/questions/8361646/…
    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 2018-02-06
    • 2019-02-05
    • 2019-02-14
    相关资源
    最近更新 更多