[Go] Use code to describe the WCF configuration file

Source: Internet
Author: User

Go from: Use code to describe a WCF configuration file

At the time of application deployment, the WCF client needs to modify the address URL of the program configuration file because of the change of the server address, the manual modification is inconvenient, but also causes the error, so try to describe the configuration of the WCF configuration file using code method, by entering the server IP address in the software, Dynamically modify the URL of the access, so that it is convenient, no error, causing the program to run abnormally.

Below I will describe a WCF deployment file in code mode:

Configuration files for WCF clients:

<?XML version= "1.0" encoding= "Utf-8"?>  <Configuration>      <System.ServiceModel>          <Bindings>              <Wshttpbinding>                  <bindingname= "Wshttpbinding_imainservice"Closetimeout= "00:01:00"Opentimeout= "00:01:00"ReceiveTimeout= "00:10:00"Sendtimeout= "00:01:00"bypassproxyonlocal= "false"TransactionFlow= "false"HostNameComparisonMode= "StrongWildcard"maxbufferpoolsize= "524288"MaxReceivedMessageSize= "65536"messageencoding= "Text"textencoding= "Utf-8"Usedefaultwebproxy= "true"allowcookies= "false">                      <ReaderquotasmaxDepth= "+"Maxstringcontentlength= "8192"Maxarraylength= "16384"Maxbytesperread= "4096"Maxnametablecharcount= "16384" />                      <reliablesessionordered= "true"InactivityTimeout= "00:10:00"enabled= "false" />                      <SecurityMode= "Message">                          <TransportclientCredentialType= "Windows"Proxycredentialtype= "None"Realm="" />                          <messageclientCredentialType= "Windows"negotiateservicecredential= "true"Algorithmsuite= "Default"Establishsecuritycontext= "true" />                      </Security>                  </binding>              </Wshttpbinding>          </Bindings>          <Client>              <EndpointAddress= "http://localhost:8888/DataCenter.Factory/MainService/"binding= "Wshttpbinding"bindingconfiguration= "Wshttpbinding_imainservice"Contract= "Imainservice"name= "Wshttpbinding_imainservice">                  <Identity>                      <servicePrincipalNamevalue= "HOST/WIN-QFIKKT28EHC" />                  </Identity>              </Endpoint>          </Client>      </System.ServiceModel>  </Configuration>

The code described above is used in programming: Here the client references the WCF service namespace defined as DATACENTERFATORYC, and the client Access object is Datacenterfatoryc.mainserviceclient MainServiceClient1;

usingSystem.ServiceModel;       Wshttpbinding Bindins;      Datacenterfatoryc.mainserviceclient MainServiceClient1; Private voidMainform_load (Objectsender, EventArgs e) {Bindins=NewWshttpbinding ();//Set BindingsBindins.closetimeout = Timespan.parse ("00:01:00"); Bindins.opentimeout= Timespan.parse ("00:01:00"); Bindins.receivetimeout= Timespan.parse ("00:10:00"); Bindins.sendtimeout= Timespan.parse ("00:01:00"); Bindins.bypassproxyonlocal=false; Bindins.transactionflow=false; Bindins.hostnamecomparisonmode=Hostnamecomparisonmode.strongwildcard; Bindins.maxbufferpoolsize=524288; Bindins.maxreceivedmessagesize=65535; Bindins.messageencoding=Wsmessageencoding.text; Bindins.textencoding=Encoding.UTF8; Bindins.usedefaultwebproxy=true; Bindins.ReaderQuotas.MaxDepth= +; Bindins.ReaderQuotas.MaxStringContentLength=8192; Bindins.ReaderQuotas.MaxArrayLength=16383; Bindins.ReaderQuotas.MaxBytesPerRead=4096; Bindins.ReaderQuotas.MaxNameTableCharCount=16384; Bindins.ReliableSession.Ordered=true; Bindins.ReliableSession.InactivityTimeout= Timespan.parse ("00:10:00"); Bindins.ReliableSession.Enabled=false; Bindins.Security.Mode=Securitymode.message; Bindins.Security.Transport.ClientCredentialType=httpclientcredentialtype.windows; Bindins.Security.Transport.ProxyCredentialType=Httpproxycredentialtype.none; Bindins.Security.Message.ClientCredentialType=messagecredentialtype.windows; Bindins.Security.Message.NegotiateServiceCredential=true; Bindins.Security.Message.AlgorithmSuite=System.ServiceModel.Security.SecurityAlgorithmSuite.Default; Bindins.Security.Message.EstablishSecurityContext=true; stringAddress ="http://localhost:8888/DataCenter.Factory/MainService/";//URL of the service endpointMainServiceClient1 =NewDatacenterfatoryc.mainserviceclient (Bindins,Newendpointaddress (address));      Mainserviceclient1.open (); }

Through the parameter setting of the Bindins, can effectively describe the access process of some problems, such as uploading and downloading large files, big data tables are dependent on the setting of important parameters, otherwise there will be abnormal errors in the operation, which we should pay attention to.

[Go] Use code to describe the WCF configuration file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.