wcf - francstratton.com multiple endpoint...wcf deployment wcf deploying service with multiple...
TRANSCRIPT
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.
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
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)
WCF Multiple Endpoint Configuration.docx Page 3
Configure the WCF Service via New Service Element Wizard
Open the Configurator
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
WCF Multiple Endpoint Configuration.docx Page 15
Configure the WCF Service
Configure the First Endpoint (netTcpBinding)
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.
WCF Multiple Endpoint Configuration.docx Page 31
Dynamically Produce a .svc File Using Configuration Based Activation
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>
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
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>
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.
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);