Let's take a look at the second article of WCF, that is, the second article of WCF that carries multiple interfaces.

Source: Internet
Author: User

Let's take a look at the second article of WCF, that is, the second article of WCF that carries multiple interfaces.

Uncle Wang has raised a large number of pigs and made a lot of money. However, it has recently been found that raising chicken can also make a lot of money, just like starting to raise chicken after expanding the business. In another two years, he found that the market had a high demand for dogs and he began to raise dogs. So how can he modify it? It is not easy to modify the places where pigs live and put ducks and dogs in it. We need to expand it, build a duck ring and a dog ring. Now let's see

Step 1: Define three interfaces

1 swine contract 2 // <summary> 3 // service contract 4 // </summary> 5 [ServiceContract] 6 public interface IPigService 7 {8 [OperationContract] 9 string pig (); 10} 11 Duck maintenance contract 12 [ServiceContract] 13 public interface IDuckService14 {15 [OperationContract] 16 string Duck (); 17} 18 Dog maintenance contract 19 20 [ServiceContract] 21 public interface IDogService22 {23 [OperationContract] 24 string Dog (); 25}Interface

Step 2: implement the content of the three interfaces (I put it in the same class. In fact, we do not recommend that you do this, so that you can keep the single feature for easy maintenance)

1 public class WcfService: IPigService, IDogService, IDuckService 2 {3 public string Pig () 4 {5 return "Hello, I am a swine professional"; 6} 7 8 public string Duck () 9 {10 return "hello, I started to expand the duck business"; 11} 12 13 public string Dog () 14 {15 return "hello, the Dog business is good, I also started to expand "; 16} 17}Implementation Interface

Step 3: implement the server

1 For other code, see article 2 host. addServiceEndpoint (typeof (IPigService), binding, ""); 3 host. addServiceEndpoint (typeof (IDogService), binding, ""); 4 host. addServiceEndpoint (typeof (IDuckService), binding ,"");Core code

Step 4: client reference. The effect is as follows:

This article is simple, but I think it is very useful. Next post sending and receiving of handwritten Headers

Source code

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.