The OperationContract of WCF

Source: Internet
Author: User

The main point here is the same name exception:

       [ServiceContract]        publicinterface  iuserinfo        {                [ OperationContract]                string showname (string  name);                [OperationContract]                 string showname ();        }    

For OperationContract with the same name, if the client references the service, the exception is reported as follows:

Workaround:

[ServiceContract]          Public Interface Iuserinfo        {                [OperationContract]                string showname (string  name);

Set alias [OperationContract (Name= "Shownamedefault")] string showname (); }

Such a client-side reference does not report an exception, but ShowName overloads, which do not work, are referenced in detail as follows:

If you need to use ShowName with the same name, you need to customize instead of using auto-generated:

classUserinfoserviceclient:clientbase<iuserinfo>, Iuserinfo { Public stringShowName () {return  This.            Channel.shownamedefault (); }             Public stringShowName (stringname) {                  return  This.            Channel.showname (name); }            #regionIuserinfo Operation not implemented Publictask<string> Shownameasync (stringname) {                  Throw Newnotimplementedexception (); }             Public stringShownamedefault () {Throw Newnotimplementedexception (); }             Publictask<string>Shownamedefaultasync () {Throw Newnotimplementedexception (); }            #endregion      }
Static void Main (string[] args)                {                      new  userinfoserviceclient ();                      Console.WriteLine (client. ShowName ());                        Console.readkey ();                }

The OperationContract of WCF

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.