1 回答
![?](http://img1.sycdn.imooc.com/533e4c9c0001975102200220-100-100.jpg)
TA贡献1826条经验 获得超6个赞
当我遇到同样的问题时,我使用了最后一个构造函数:
MyServiceClient(Binding binding, EndpointAddress remoteAddress). 在类构造函数中将服务 uri 作为参数传递,然后仅使用默认设置:
private MyServiceClient = _service;
public MyClass(string serviceUri)
{
if (string.IsNullOrEmpty(serviceUri))
{
_service = new MyServiceClient();
}
else
{
var binding = new System.ServiceModel.BasicHttpBinding() { MaxReceivedMessageSize = int.MaxValue };
var endpoint = new System.ServiceModel.EndpointAddress(serviceUri);
_service = new MyServiceClient (binding, endpoint);
}
}
但是,我不知道您可以按照Marc_s 的回答(也在dotnetstep 的评论中链接)中演示的那样将配置文件外部化- 如果我知道这一点,我可能会使用它。
顺便说一句,请注意,在我的代码中,如果您传递 null 或空字符串,serviceModel则预计会在配置文件中找到。
- 1 回答
- 0 关注
- 298 浏览
添加回答
举报