WCF Client C # code configuration config file

Source: Internet
Author: User

Not much to say, directly on the code bar ....

Bindings configuration in the service-side Web. config file

   <Bindings>      <Wshttpbinding>        <bindingname= "httpconf"Closetimeout= "10:10:10"Opentimeout= "10:10:10"ReceiveTimeout= "10:10:10"Sendtimeout= "10:10:10"allowcookies= "true"bypassproxyonlocal= "false"HostNameComparisonMode= "StrongWildcard"maxbufferpoolsize= "2147483647"MaxReceivedMessageSize= "2147483647" >          <reliablesessionordered= "true"InactivityTimeout= "00:20:00"enabled= "false" />          <SecurityMode= "Message">            <TransportclientCredentialType= "Windows"Proxycredentialtype= "None"Realm="" />            <messageclientCredentialType= "Windows"negotiateservicecredential= "true"Algorithmsuite= "Default" />          </Security>        </binding>      </Wshttpbinding> </Bindings>

Behavior configuration in the service-side Web. config file

<Behaviorname= "Card_WcfService.WCF.CardInfoServiceBehavior">          <DataContractSerializerMaxitemsinobjectgraph= "2147483647" />          <Servicemetadatahttpgetenabled= "true" />          <servicetimeoutsTransactionTimeout= "00:10:00" />          <ServicedebugIncludeexceptiondetailinfaults= "false" />          <servicethrottlingMaxconcurrentcalls= "2147483647"maxconcurrentinstances= "2147483647"maxconcurrentsessions= "2147483647" /> </Behavior>

Service configuration in the server Web. config file

 <Servicebehaviorconfiguration= "Card_WcfService.WCF.CardInfoServiceBehavior"name= "Card_WcfService.WCF.CardInfoService">        <EndpointAddress=""binding= "Wshttpbinding"Contract= "Card_systemapi.icardinfoservice"bindingconfiguration= "httpconf">          <Identity>            <DNSvalue= "localhost" />          </Identity>        </Endpoint>            </Service>

Here's what I want, and it took me half a day to get it.
Client code Registration configuration file

 public class Clientfactory<tclient>: IDisposable {static endpointaddress serviceaddress;        static Wshttpbinding binding;        Channelfactory<tclient> Factory;        TClient proxy;        OperationContextScope scope;            Public TClient CreateClient () {factory = new channelfactory<tclient> (binding, serviceaddress); foreach (OperationDescription op in factory. Endpoint.Contract.Operations) {Datacontractserializeroperationbehavior Datacontractbehavior = O P.behaviors.find<datacontractserializeroperationbehavior> () as Datacontractserializeroperationbeh                Avior if (datacontractbehavior! = null) {datacontractbehavior.maxitemsinobjectgraph = 2147483                647; }} proxy = Factory.            CreateChannel (); ((Iclientchannel) proxy).            Faulted + = new EventHandler (a_faulted); scope = new OperAtioncontextscope (((iclientchannel) proxy)); var Curid = Cachestrategy.curuser = = null?            Guid.Empty:CacheStrategy.CurUser.AutoID;            messageheader<guid> mhg = new messageheader<guid> (Curid); MessageHeader untyped = mhg.            Getuntypedheader ("token", "ns");            OPERATIONCONTEXT.CURRENT.OUTGOINGMESSAGEHEADERS.ADD (untyped);        return proxy; } void A_faulted (object sender, EventArgs e) {//todo: exception is not found here} public void Disp OSE () {try {scope.                Dispose (); ((Iclientchannel) proxy).                Close (); Factory.            Close (); } catch {}} static clientfactory () {var surl = Configu            rationmanager.appsettings["serviceurl"]; var iname = typeof (TClient). Fullname.substring ("Card_systemapi.i").            Length); var sname = string.         Format ("{0}.svc", iname);   var url = path.combine (sURL, sname);            serviceaddress = new EndpointAddress (URL);            binding = new Wshttpbinding (); Binding.            Closetimeout = new TimeSpan (10, 10, 10); Binding.            Opentimeout = new TimeSpan (10, 10, 10); Binding.            Sendtimeout = new TimeSpan (10, 10, 10); Binding.            ReceiveTimeout = new TimeSpan (10, 10, 10); Binding.            MaxReceivedMessageSize = 2147483647; Binding.            Maxbufferpoolsize = 2147483647; Binding.        AllowCookies = true; }    }

QQ Group number: 242251580 identity authentication:. NET Technical Discussion

If reproduced, please keep the original address: http://www.cnblogs.com/hank-hu/p/4663568.html

WCF Client C # code configuration config file

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.