ASP. NET calls multiple endpoints and multiple contract WCF services

Source: Internet
Author: User

This article describes how ASP. NET calls multiple endpoint and multiple contract WCF services, including the following implementation:

    • ASP. NET calls the WCF Service
    • WCF Service library, on the IIS HOST
    • Multi-endpoint and multi-contract WCF Service (implemented in one service *. SVC)
    • Dynamic reference of the WCF Service

All the source code in this article can be downloaded here (ASP. NET calls the source code of the Multi-endpoint multi-contract WCF Service ).

Code Structure

The code structure is as follows: three projects, one is that the WCF Service (iis host) contains an empty *. SVC, the other is the WCF Service library, and the other is that the ASP. NET client calls the WCF Service. The advantage of using the WCF Service library is flexibility. You can choose the host WCF Service, which can be IIS/WebService, Windows service, or custom application.

Implement multiple contract and endpoint in one *. svc ,:

Let's first talk about the WCF Service library, which includes some service contract and implementations. Of course, you can extract them from the contract and put them on another DLL. Here we put them together for convenience of demonstration. To implement multiple contract and endpoint for one *. SVC, note that this service must implement multiple contract interfaces. Here we use local classes to implement: partial class

 

Iservice2 is like this:

 

Web. config configuration of WCF Service: (one *. SVC implements multiple contract and Endpoint)

Service1.svc of the WCF Service is an empty shell, but you need to modify it to point the implementation to the WCF Service Library:

After running the WCF Service, it is accessible:

Calling WCF Service on ASP. NET client :( multiple service contract interfaces can be called respectively)

Note: Here is a direct static service reference, which can be used to dynamically create a WCF Service reference. The code is no longer here, and it is very simple.

On the ASP. NET client web. config:

Source code download

All the source code in this article can be downloaded here (ASP. NET calls the source code of the Multi-endpoint multi-contract WCF Service ).

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.