Software & Finance





Visual Studio.NET - WCF Test Service Library (DLL)





 

Here is the sample source code for WCF Test Service Library.

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

 

namespace Wcf_Test_ServiceLibrary

{

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.

    [ServiceContract]

    public interface ITestService

    {

        [OperationContract (Name="Int")]

        string GetData(int value);

 

        [OperationContract(Name = "String")]

        string GetData(string value);

    }

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

 

namespace Wcf_Test_ServiceLibrary

{

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.

    public class TestService : ITestService

    {

        public string GetData(int value)

        {

            return string.Format("You entered: {0}", value);

        }

 

        public string GetData(string value)

        {

            return string.Format("You entered: {0}", value);

        }

    }

}

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

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

    <services>

      <service name="Wcf_Test_ServiceLibrary.TestService">

        <host>

          <baseAddresses>

            <add baseAddress = "http://localhost:8732/Design_Time_Addresses/Wcf_Test_ServiceLibrary/TestService/" />

          </baseAddresses>

        </host>

        <!-- Service Endpoints -->

        <!-- Unless fully qualified, address is relative to base address supplied above -->

        <endpoint address ="" binding="wsHttpBinding" contract="Wcf_Test_ServiceLibrary.ITestService">

          <!--

              Upon deployment, the following identity element should be removed or replaced to reflect the

              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity

              automatically.

          -->

          <identity>

            <dns value="localhost"/>

          </identity>

        </endpoint>

        <!-- Metadata Endpoints -->

        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->

        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

      </service>

    </services>

    <behaviors>

      <serviceBehaviors>

        <behavior>

          <!-- To avoid disclosing metadata information,

          set the value below to false and remove the metadata endpoint above before deployment -->

          <serviceMetadata httpGetEnabled="True"/>

          <!-- To receive exception details in faults for debugging purposes,

          set the value below to true.  Set to false before deployment

          to avoid disclosing exception information -->

          <serviceDebug includeExceptionDetailInFaults="False" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

 

</configuration>

 

 

Here is how hosting is done locally on the development machine.

 

 

 

Here is how testing is done using WCF Test Client

 

 

Click here to download the SCF Test Service Library (DLL) Source Code