Configure WCF service with a common host address

by Jagadish Pulakhandam on 5/10/2011 7:25:07 AM
Rated 0 from 0 votes
Brief: Demonstrates on configuring a WCF Service with a common host for all bindings.
Posted to: Windows Communication Foundation - Bindings
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

Demonstrates the following (see attached video):

  • Create a very basic WCF Service Library from the scratch (using Visual Studio 2010)
  • Configure WCF Service using "WCF Service Configuration Editor"
  • Configure both "BasicHttpBinding" and "MexHttpBinding" with same common Host (using "WCF Service Configuration Editor"
  • Execute by hosting through "WCF Service Host"
  • Test the service using "WCF Test Client"
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Text;
05.using System.ServiceModel;
06. 
07.namespace SampleCalcService
08.{
09.    [ServiceContract]
10.    public interface ICalcService
11.    {
12.        [OperationContract]
13.        int GetSum(int a, int b);
14.    }
15.}
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Text;
05. 
06.namespace SampleCalcService
07.{
08.    public class CalcService: ICalcService
09.    {
10.        public int GetSum(int a, int b)
11.        {
12.            return (a + b);
13.        }
14.    }
15.}
01.<?xml version="1.0" encoding="utf-8" ?>
02.<configuration>
03. 
04.  <system.web>
05.    <compilation debug="true" />
06.  </system.web>
07.  
08. 
09.  <system.serviceModel>
10.    <behaviors>
11.      <serviceBehaviors>
12.        <behavior name="SampleCalcSvcBehavior">
13.          <serviceDebug includeExceptionDetailInFaults="true" />
14.          <serviceMetadata httpGetEnabled="true" />
15.        </behavior>
16.      </serviceBehaviors>
17.    </behaviors>
18.    <services>
19.      <service behaviorConfiguration="SampleCalcSvcBehavior" name="SampleCalcService.CalcService">
20.        <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
21.          name="SampleCalcSvcBasicHttpEndPoint" contract="SampleCalcService.ICalcService" />
22.        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
23.          name="SampleCalcSvcMexHttpEndPoint" contract="IMetadataExchange" />
24.        <host>
25.          <baseAddresses>
26.            <add baseAddress="http://localhost:8080/SampleCalcSvc" />
27.          </baseAddresses>
28.        </host>
29.      </service>
30.    </services>
31.  </system.serviceModel>
32.</configuration>



Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion
0

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following

Video/Screen Recording (may not have audio narration/annotations)
You need to Login or Join for FREE to download the following