1 回答

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
當(dāng)我遇到同樣的問(wèn)題時(shí),我使用了最后一個(gè)構(gòu)造函數(shù):
MyServiceClient(Binding binding, EndpointAddress remoteAddress). 在類(lèi)構(gòu)造函數(shù)中將服務(wù) uri 作為參數(shù)傳遞,然后僅使用默認(rèn)設(shè)置:
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 的評(píng)論中鏈接)中演示的那樣將配置文件外部化- 如果我知道這一點(diǎn),我可能會(huì)使用它。
順便說(shuō)一句,請(qǐng)注意,在我的代碼中,如果您傳遞 null 或空字符串,serviceModel則預(yù)計(jì)會(huì)在配置文件中找到。
- 1 回答
- 0 關(guān)注
- 316 瀏覽
添加回答
舉報(bào)