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 ).