Page 1
WCF DEPLOYMENT
WCF Deploying service with multiple endpoints
CSS
11/8/2012
This document explains how to configure a WCF service to expose multiple endpoints, use configuration based activation (CBA) to deploy to IIS Server without the need for a .svc file. Note: This instruction
assumes that a WCF Service has already been created.
Page 2
WCF Multiple Endpoint Configuration.docx Page 1
Contents Prerequisites ................................................................................................................................................. 2
Configure the WCF Service via New Service Element Wizard ...................................................................... 3
Open the Configurator .............................................................................................................................. 3
Stepping Through the New Service Element Wizard ................................................................................ 5
Configure the WCF Service ......................................................................................................................... 15
Configure the First Endpoint (netTcpBinding) ........................................................................................ 15
Adding the Base Address ........................................................................................................................ 17
Configure Message Exchange (mex) Endpoint ....................................................................................... 19
Add a New Service Behavior ................................................................................................................... 25
Dynamically Produce a .svc File Using Configuration Based Activation ................................................. 31
The Completed app.config File (only 1 endpoint): ..................................................................................... 37
Add Any Number of Additional Endpoints .................................................................................................. 38
Completed app.config with an Additional Endpoint ................................................................................... 42
Files Created on IIS Server (After Publish) .................................................................................................. 43
How to Call a Method on a Proxy with Multiple Endpoints ....................................................................... 45
Page 3
WCF Multiple Endpoint Configuration.docx Page 2
Prerequisites
Visual Studio 2012
Windows Server 2008 R2 running IIS 7.5
Working WCF Service Library project (doesn’t include a .svc file)
Page 4
WCF Multiple Endpoint Configuration.docx Page 3
Configure the WCF Service via New Service Element Wizard
Open the Configurator
Page 5
WCF Multiple Endpoint Configuration.docx Page 4
Page 6
WCF Multiple Endpoint Configuration.docx Page 5
Stepping Through the New Service Element Wizard
Page 7
WCF Multiple Endpoint Configuration.docx Page 6
Page 8
WCF Multiple Endpoint Configuration.docx Page 7
Page 9
WCF Multiple Endpoint Configuration.docx Page 8
Page 10
WCF Multiple Endpoint Configuration.docx Page 9
Page 11
WCF Multiple Endpoint Configuration.docx Page 10
Page 12
WCF Multiple Endpoint Configuration.docx Page 11
Page 13
WCF Multiple Endpoint Configuration.docx Page 12
Note: This wizard is stepping you through creating the initial service endpoint (netTCPBinding). The
other endpoint will be created using the WCF Service Configuration Manager
Page 14
WCF Multiple Endpoint Configuration.docx Page 13
Page 15
WCF Multiple Endpoint Configuration.docx Page 14
Page 16
WCF Multiple Endpoint Configuration.docx Page 15
Configure the WCF Service
Configure the First Endpoint (netTcpBinding)
Page 17
WCF Multiple Endpoint Configuration.docx Page 16
Page 18
WCF Multiple Endpoint Configuration.docx Page 17
Adding the Base Address
Note: In this example, the address for the pre-configured IIS site that hosts this service is entered
instead of the default path.
Page 19
WCF Multiple Endpoint Configuration.docx Page 18
Page 20
WCF Multiple Endpoint Configuration.docx Page 19
Configure Message Exchange (mex) Endpoint
Page 21
WCF Multiple Endpoint Configuration.docx Page 20
Page 22
WCF Multiple Endpoint Configuration.docx Page 21
Page 23
WCF Multiple Endpoint Configuration.docx Page 22
Page 24
WCF Multiple Endpoint Configuration.docx Page 23
Page 25
WCF Multiple Endpoint Configuration.docx Page 24
Page 26
WCF Multiple Endpoint Configuration.docx Page 25
Add a New Service Behavior
Page 27
WCF Multiple Endpoint Configuration.docx Page 26
Page 28
WCF Multiple Endpoint Configuration.docx Page 27
Page 29
WCF Multiple Endpoint Configuration.docx Page 28
Page 30
WCF Multiple Endpoint Configuration.docx Page 29
Page 31
WCF Multiple Endpoint Configuration.docx Page 30
Page 32
WCF Multiple Endpoint Configuration.docx Page 31
Dynamically Produce a .svc File Using Configuration Based Activation
Page 33
WCF Multiple Endpoint Configuration.docx Page 32
Page 34
WCF Multiple Endpoint Configuration.docx Page 33
Page 35
WCF Multiple Endpoint Configuration.docx Page 34
Page 36
WCF Multiple Endpoint Configuration.docx Page 35
Page 37
WCF Multiple Endpoint Configuration.docx Page 36
Page 38
WCF Multiple Endpoint Configuration.docx Page 37
The Completed app.config File (only 1 endpoint):
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="DevConnectionString" providerName="System.Data.SqlClient" connectionString="j7IDvLI+y4h21UmDLT1q1ov/fyGurdahBH2ZYXv7yAmWDiwshRe7Tqymf0PPdQ6fLl2AeX+PS2NUS9+MrWRPheWb/+yYuQWJlYl/rQFWgOAh9ZdrG7gzBJitcoDF+P7k" /> <add name="QAConnectionString" providerName="System.Data.SqlClient" connectionString="j7IDvLI+y4i2xex63kXidncnPwG/xMviipHr6/TXWjoF9y/QiF8oL6ymf0PPdQ6fWiTDuI3UJ7fYpRv3X7CIsfD8CT36qTDDy69Y8Yhw6V9oFVgtRZeXeFcAaHQFxgcl2hzW44PebD4xmiVguxWGPQ==" /> </connectionStrings> <system.web> <compilation debug="true" /> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <bindings> <netTcpBinding> <binding name="DemoServiceBindingConfig"> <security mode="None" /> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="DemoServiceTcpBehavior"> <serviceMetadata httpGetEnabled="false" /> <serviceDebug /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="DemoServiceTcpBehavior" name="WcfDemoService.DHSService"> <endpoint address="demoTCP" binding="netTcpBinding" bindingConfiguration="DemoServiceBindingConfig" name="DemoServiceTCP" contract="WcfDemoService.IDHSService" /> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="DemoServiceMetaDataExchange" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://win-7aqosrmnsqi:8080/Services/" /> </baseAddresses> </host> </service> </services> <serviceHostingEnvironment multipleSiteBindingsEnabled="true"> <serviceActivations> <add relativeAddress="DHSService.svc" service="WcfDemoService.DHSService" /> </serviceActivations> </serviceHostingEnvironment> </system.serviceModel> </configuration>
Page 39
WCF Multiple Endpoint Configuration.docx Page 38
Add Any Number of Additional Endpoints
Page 40
WCF Multiple Endpoint Configuration.docx Page 39
Page 41
WCF Multiple Endpoint Configuration.docx Page 40
Note: The HttpGetEnabled Property Gets or sets a value that indicates whether to publish service
metadata for retrieval using an HTTP/GET request. If this is set to True, then the service metadata
(WSDL) will be displayed via HTTP protocol. This can be viewed in the browser by connecting to the
base address of the service. An example URL would be:
http://YourIISServer/YourWebsiteDirectory/DHSService.svc?WSDL
Page 42
WCF Multiple Endpoint Configuration.docx Page 41
Page 43
WCF Multiple Endpoint Configuration.docx Page 42
Completed app.config with an Additional Endpoint
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="DevConnectionString" providerName="System.Data.SqlClient" connectionString="j7IDvLI+y4h21UmDLT1q1ov/fyGurdahBH2ZYXv7yAmWDiwshRe7Tqymf0PPdQ6fLl2AeX+PS2NUS9+MrWRPheWb/+yYuQWJlYl/rQFWgOAh9ZdrG7gzBJitcoDF+P7k" /> <add name="QAConnectionString" providerName="System.Data.SqlClient" connectionString="j7IDvLI+y4i2xex63kXidncnPwG/xMviipHr6/TXWjoF9y/QiF8oL6ymf0PPdQ6fWiTDuI3UJ7fYpRv3X7CIsfD8CT36qTDDy69Y8Yhw6V9oFVgtRZeXeFcAaHQFxgcl2hzW44PebD4xmiVguxWGPQ==" /> </connectionStrings> <system.web> <compilation debug="true" /> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <bindings> <netTcpBinding> <binding name="DemoServiceBindingConfig"> <security mode="None" /> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="DemoServiceTcpBehavior"> <serviceMetadata httpGetEnabled="true" policyVersion="Default" /> <serviceDebug /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="DemoServiceTcpBehavior" name="WcfDemoService.DHSService"> <endpoint address="demoTCP" binding="netTcpBinding" bindingConfiguration="DemoServiceBindingConfig" name="DemoServiceTCP" contract="WcfDemoService.IDHSService" /> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="DemoServiceMetaDataExchange" contract="IMetadataExchange" /> <endpoint address="DemoServiceBasic" binding="basicHttpBinding" bindingConfiguration="" name="DemoServiceBasicHttp" contract="WcfDemoService.IDHSService" /> <host> <baseAddresses> <add baseAddress="net.tcp://win-7aqosrmnsqi:8080/Services/" /> </baseAddresses> </host> </service> </services> <serviceHostingEnvironment multipleSiteBindingsEnabled="true"> <serviceActivations> <add relativeAddress="DHSService.svc" service="WcfDemoService.DHSService" /> </serviceActivations> </serviceHostingEnvironment> </system.serviceModel> </configuration>
Page 44
WCF Multiple Endpoint Configuration.docx Page 43
Files Created on IIS Server (After Publish)
Note: This is the main directory that the service was published during deployment. To see the
assemblies that were copied, open the bin folder as shown in the image above.
Page 45
WCF Multiple Endpoint Configuration.docx Page 44
Page 46
WCF Multiple Endpoint Configuration.docx Page 45
How to Call a Method on a Proxy with Multiple Endpoints
When calling a method using a service proxy that has multiple endpoints defined, it is important to do
the following:
var proxy = new YourProxyClass.YourServiceNameClient(“YourEndPointName");
proxy.YourServiceOperation();
Actual Example:
var proxy = new DHSAVProxy.DHSServiceClient("DemoServiceHTTP");
. . .
list = proxy.GetCityStateForZipcode(parms);