By adding the code generated after the service reference, you know that you first want to set the properties of the basic connection and set the address of the WCF service:
Here I set up the factory class as follows:
usingSystem;usingSystem.ServiceModel;usingSystem.ServiceModel.Channels;usingshoppingmall.enums;namespaceshoppingmall.clientbll{ Public classEndpointfactory {Private StaticBinding getbindingforendpoint (endpointconfigurationenums endpointconfiguration) {if(Endpointconfiguration = =Endpointconfigurationenums.basichttpbinding_icustomerservice)) {BasicHttpBinding result=NewBasicHttpBinding (); Result. MaxBufferSize=int. MaxValue; Result. Readerquotas=System.Xml.XmlDictionaryReaderQuotas.Max; Result. MaxReceivedMessageSize=int. MaxValue; Result. AllowCookies=true; returnresult; } Throw NewInvalidOperationException (string. Format ("An endpoint with the name ' {0} ' could not be found. ", endpointconfiguration)); } Private Staticendpointaddress getendpointaddress (endpointconfigurationenums endpointconfiguration) {if(Endpointconfiguration = =Endpointconfigurationenums.basichttpbinding_icustomerservice)) { return NewEndpointAddress ("http.//Your address"); } Throw NewInvalidOperationException (string. Format ("An endpoint with the name ' {0} ' could not be found. ", endpointconfiguration)); } Public StaticBinding getdefaultbinding () {returnGetbindingforendpoint (Endpointconfigurationenums.basichttpbinding_icustomerservice); } Public Staticendpointaddress getdefaultendpointaddress () {returngetendpointaddress (Endpointconfigurationenums.basichttpbinding_icustomerservice); } }}
Then, when the client calls, it needs to call the class to inherit the ClientBase class and inherit the WCF interface, which is the type of the WCF interface.
And to inherit the constructor of the clientbase in the constructor parameters of the client call class, instantiate the address of the basic and the WCF service
Finally, the service method is invoked by inheriting the channel mode of ClientBase, the full code is as follows:
usingMicrosoft.Extensions.Configuration;usingShoppingmall.iservice;usingShoppingmall.model;usingSystem.Collections.Generic;usingSystem.ServiceModel;namespaceshoppingmall.clientbll{ Public classCustomerbll:clientbase<icustomerservice>, Icustomerservice { Publiciconfigurationroot configuration; PublicCUSTOMERBLL ():Base(Endpointfactory.getdefaultbinding (), endpointfactory.getdefaultendpointaddress ()) {} PublicList<buyer>getbuyerlist () {returnchannel.getbuyerlist (); } Public BOOLinsertbuyerinfo (Buyer info) {returnChannel.insertbuyerinfo (info); } }}
Second, WCF's service interfaces should have a corresponding tag, for example:
usingShoppingmall.model;usingSystem.Collections.Generic;usingSystem.ServiceModel;namespaceshoppingmall.iservice{/// <summary> ///User Information Processing services/// </summary>[ServiceContract] Public InterfaceIcustomerservice {/// <summary> ///get a list of buyers/// </summary> /// <returns></returns>[OperationContract] List<Buyer>getbuyerlist (); /// <summary> ///Add buyer Information/// </summary> /// <returns></returns>[OperationContract]BOOLinsertbuyerinfo (Buyer info); }}
In this way, the interface tag:
ServiceContract.
Method Tags:
OperationContract
. NET core downgrade. WCF method notation for the Nett framework framework