Learning WCF Chapter1 Exposing Multiple Service Endpoints

So far in this chapter,I have shown you different ways to create services,
how to expose a service endpoint and metadata exchange endpoint,
how to generate client proxies,
how to work with metadata,
and how to configure service behaviors.
In this section,I’ll place the emphasis on endpoints,binding configuration,and allocation of assemblies for a more complex solution.

WCF includes a number of standard bindings that allow you to quickly configure a service for a particular set of protocols.
Clients must use compatible protocols when they communicate with each endpoint.
Services can expose multiple endpoints for the same service contract in order to expose functionality over different protocols.
For example,a service may be called by internal clients over TCP,but by external clients over HTTP.
In addition to supporting different protocols,internal and external clients may not have access to the same service contracts.
Some operations may be allowed only by clients within the domain,while others are publicly available to remote clients on the Internet.

In this lab you will configure multiple endpoints for a service to support different endpoint and binding configurations.
In the process you’ll explore the following concepts:
• Hosting multiple services
• Configuring multiple endpoints for a service
• Accessing a service from a Windows client application
• Initializing proxies from multiple endpoint and binding configurations
• Comparing proxy generation to sharing types between services and clients

Lab: Hosting Multiple Services and Sharing Types

In this lab,you’ll modify an existing solution to implement a service contract and an administrative contract on two distinct services.
You’ll then host each service in the same host process,a console application.
An internal client presumed to be behind the firewall will consume each service using network protocols such as TCP and named pipes.
This client will have access to service operations exposed by the service contract and administrative contract.
An external client,presumed to be accessing the service over the Internet will have access only to operations exposed by the service contract over HTTP.
The internal client will share class libraries to access service contracts,while the external client will use traditional methods for generating service proxies.

Implementing multiple contracts on a service
In this section,you’re going to implement the predefined service contracts on two distinct services.
Each service will expose two contracts: one for business functionality core to the service,the other for administrative functionality.
Both services will implement the same administrative contract.
This illustrates an example of contract factoring for reuse.
1. Start by opening the solution <YourLearningWCFPath>\Labs\Chapter1\MultiContractService\MultiContractService.sln.
This solution contains several shell projects,including a service library,a host,and two Windows client applications as follows:

BusinessServiceContracts
A class library containing three contracts: IAdmin, IServiceA,and IServiceB.
IAdmin defines administrative operations.
IServiceA and IServiceB respectively describe functionality to be exposed by ServiceA and ServiceB.

BusinessServices
A class library that will contain two services: ServiceA and ServiceB.

Host
A console application that will host ServiceA and ServiceB.

InternalClient
A windows client application that will access services behind the firewall.

ExternalClient
A windows client application that will access services over the Internet.

Note:Putting service contracts into a separate class library facilitates sharing metadata with client applications when you own both sides of the development effort.

2. The first thing you’ll do is provide an implementation for ServiceA,which is located in the BusinessServices class library.
First,take a look at the contracts you will implement.
Go to the BusinessServiceContracts project and open IServiceA.cs; you’ll see a contract with two operations.
Now open IAdmin.cs and you’ll see another contract with two different operations.
To implement these contracts,go to the BusinessServices project.
First,add a reference to the BusinessServiceContracts project so you can access the contracts it defines.
Then open ServiceA.cs and add a using statement for the BusinessServiceContracts namespace, as shown here:

using BusinessServiceContracts;

Modify the definition of ServiceA so that it derives from IServiceA and IAdmin as follows:

public class ServiceA : IServiceA, IAdmin

Implement both contracts implicitly.
You can use a shortcut by hovering your mouse over IServiceA and using the smart tag to select “Implement interface IServiceA,” as shown in Figure 1-29.

时间: 2024-11-16 20:46:19

Learning WCF Chapter1 Exposing Multiple Service Endpoints的相关文章

Learning WCF Chapter1 Generating a Service and Client Proxy

In the previous lab,you created a service and client from scratch without leveraging the tools available to WCF developers. Although this helps you to understand the raw requirements for sending messages between clients and services,in reality,develo

Learning WCF Chapter1 Creating a New Service from Scratch

You’re about to be introduced to the WCF service. This lab isn’t your typical “Hello World”—it’s “Hello Indigo”! In this lab,you will learn how to build a new WCF service and in the process learn the minimum requirements of service development and co

Learning WCF Chapter1 Summary

SummaryThis chapter covered a lot of ground,beginning with a look at the purpose of WCF,the problems it solves and its alignment with SOA,through discussion of the fundamentals developers should know before they begin working with WCF. I also touched

Hosting Multiple Service Implementations On The Same Port With WCF

Hosting Multiple Service Implementations On The Same Port With WCF Recently I have been playing around with WCF and Visual Studio 2008.  I was building a set of web services.  The project consisted of two difference service interfaces (IServiceA and

Learning WCF Chapter2 Service Description

While messaging protocols are responsible for message serialization formats,there must be a way to capture the protocols required to communicate between clients and services. In Chapter 1,you worked with WSDL documents,which describe the requirements

WCF、WebAPI、WCF REST、Web Service之间的区别

在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Services.我分享一下我对Web Service.WCF以及Web API的看法. Web Service 1.它是基于SOAP协议的,数据格式是XML 2.只支持HTTP协议 3.它不是开源的,但可以被任意一个了解XML的人使用 4.它只能部署在IIS上 WCF 1.这个也是基于SOAP的,数据格式是XML 2.这个是We

转 Difference between WCF and Web API and WCF REST and Web Service

http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-REST-and-Web-Service.html Posted By : Shailendra Chauhan, 05 Apr 2013 Updated On : 13 Apr 2013 Total Views : 126,254 Keywords : web api vs wcf vs wcf r

用C#基于WCF创建TCP的Service供Client端调用

本文将详细讲解用C#基于WCF创建TCP的Service供Client端调用的详细过程 1):首先创建一个Windows Service的工程 2):生成的代码工程结构如下所示 3):我们将Service1改名为MainService 4): 添加一个Interface来定义Service的契约 4.1):截图如下所示 4.2):IOrderService.cs的代码如下所示 using System; using System.Collections.Generic; using System

WCF、Web API、WCF REST、Web Service 区别

Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS. WCF It is also based on SOAP and return data in XM