亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# 如何在運行時更新 Visual Studio 2107 xxx.exe.config 綁定?

C# 如何在運行時更新 Visual Studio 2107 xxx.exe.config 綁定?

C#
桃花長相依 2021-06-29 13:48:12
當我編譯我的 C# web 服務代碼時,會創建一個 xxx.exe.config 文件。但是,我想在運行時修改其中一個綁定。Visual Studio 生成的 xxx.exe.config 文件的示例是:<?xml version="1.0" encoding="utf-8" ?><configuration>    <system.serviceModel>        <bindings>            <basicHttpBinding>                <binding name="BasicHttpBinding_ContentService"                         messageEncoding="Mtom" />            </basicHttpBinding>        </bindings>    </system.serviceModel></configuration>我想在運行時向名為“BasicHttpBinding_ContentService”的綁定添加一些參數,相當于手動編碼:<binding name="BasicHttpBinding_ContentService"                                           messageEncoding="Mtom"              maxBufferSize="5000000"              maxBufferPoolSize="524288"              maxReceivedMessageSize="2147483648"              transferMode="Streamed" />我認為定義參數設置的 C# 代碼如下所示:using System.ServiceModel;BasicHttpBinding myBinding = new BasicHttpBinding("BasicHttpBinding_ContentService");myBinding.MaxBufferSize = 5000000;myBinding.MaxBufferPoolSize = 524288;myBinding.MaxReceivedMessageSize = 2147483648;myBinding.TransferMode = TransferMode.Streamed;但是我找不到將“myBinding”應用于我的 Visual Studio .config 文件的 C# 示例(有效)。我確實找到了在我的環境中未定義的參考類,如 ServiceHost 和 ServiceClient。注意 - 我使用的是 .NET 4.6。
查看完整描述

2 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

嘗試這樣的事情,讓我知道......


NTEGRAWSSOAPClient _wsProtheus = null; // NTEGRAWSSOAPClient is a SOAP client class generated by vs2017 on register webservice


var endpointConfiguration = NTEGRAWSSOAPClient.EndpointConfiguration.INTEGRAWSSOAP; //INTEGRAWSSOAP is a ConfigurationName of service


_wsProtheus = new NTEGRAWSSOAPClient(endpointConfiguration,new EndpointAddress("http://new address?wsdl", new SpnEndpointIdentity("your identi")));


BasicHttpBinding bind = (BasicHttpBinding)_wsProtheus.Endpoint.Binding;


bind.CloseTimeout = TimeSpan.Parse("02:00:00");

bind.OpenTimeout = TimeSpan.Parse("02:00:00");

bind.ReceiveTimeout = TimeSpan.Parse("02:00:00");

bind.SendTimeout = TimeSpan.Parse("02:00:00");

bind.MaxBufferPoolSize = Int32.MaxValue;

bind.MaxBufferSize = Int32.MaxValue;

bind.MaxReceivedMessageSize = Int32.MaxValue;


bind.ReaderQuotas.MaxDepth = 32;

bind.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;

bind.ReaderQuotas.MaxArrayLength = Int32.MaxValue;

bind.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;

bind.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;


bind.Security.Mode = BasicHttpSecurityMode.None;


查看完整回答
反對 回復 2021-07-10
  • 2 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號