. NET core downgrade. WCF method notation for the Nett framework framework

Source: Internet
Author: User

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

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.