首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何以编程方式将客户端连接到WCF服务?

如何以编程方式将客户端连接到WCF服务?
EN

Stack Overflow用户
提问于 2010-05-31 19:17:51
回答 1查看 129.5K关注 0票数 75

我正在尝试将应用程序(客户端)连接到公开的WCF服务,但不是通过应用程序配置文件,而是通过代码。

我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2015-02-20 08:26:44

您还可以做“服务参考”生成的代码所做的事情

代码语言:javascript
复制
public class ServiceXClient : ClientBase<IServiceX>, IServiceX
{
    public ServiceXClient() { }

    public ServiceXClient(string endpointConfigurationName) :
        base(endpointConfigurationName) { }

    public ServiceXClient(string endpointConfigurationName, string remoteAddress) :
        base(endpointConfigurationName, remoteAddress) { }

    public ServiceXClient(string endpointConfigurationName, EndpointAddress remoteAddress) :
        base(endpointConfigurationName, remoteAddress) { }

    public ServiceXClient(Binding binding, EndpointAddress remoteAddress) :
        base(binding, remoteAddress) { }

    public bool ServiceXWork(string data, string otherParam)
    {
        return base.Channel.ServiceXWork(data, otherParam);
    }
}

其中,IServiceX是您的WCF服务合同

然后你的客户端代码:

代码语言:javascript
复制
var client = new ServiceXClient(new WSHttpBinding(SecurityMode.None), new EndpointAddress("http://localhost:911"));
client.ServiceXWork("data param", "otherParam param");
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2943148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档