第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

引用服務(wù)時(shí)如何使用 dll 的 .config 文件?

引用服務(wù)時(shí)如何使用 dll 的 .config 文件?

C#
拉風(fēng)的咖菲貓 2021-09-19 18:44:20
我知道如果 a 中的代碼.dll想要讀取其配置文件,則必須手動(dòng)執(zhí)行。但是,如果(在同一文件中.dll)您正在引用一項(xiàng)服務(wù),那會(huì)如何搭建一些代碼并將一些配置添加到.config文件中,因此我能夠使用該服務(wù)的唯一方法是將該配置復(fù)制到主應(yīng)用程序的.config文件中。我想知道是否有人有另一種方法。我認(rèn)為它應(yīng)該使用腳手架提供的任何構(gòu)造函數(shù),但無(wú)法使其工作。這些是構(gòu)造函數(shù):MyServiceClient(string endpointConfigurationName)MyServiceClient(string endpointConfigurationName, string remoteAddress)MyServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress)MyServiceClient(Binding binding, EndpointAddress remoteAddress)和配置:<system.serviceModel>    <bindings>      <basicHttpBinding>        <binding name="BasicEndPoint" />      </basicHttpBinding>    </bindings>    <client>      <endpoint address="<service-url>"          binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"          contract="<contract>" name="BasicEndPoint" />    </client></system.serviceModel>提前致謝!
查看完整描述

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ì)在配置文件中找到。


查看完整回答
反對(duì) 回復(fù) 2021-09-19
  • 1 回答
  • 0 關(guān)注
  • 316 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)