
Step 2). Then right click on solution WcfLinq in Solution Explorer ,in context menu select
Add -> New Project , New Project window will open in that select WCF as project type and
In template Wcf Service Library ,Name it MyWcfServiceLibrary

Step 3). It will create two .cs , one for interface IService.cs and second is Service.cs.
Rename both files “(IServiceTest.cs and ServiceTest.cs respectively) “or leave as it is.
In IServiceTest.cs file code replace with below code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace MyWcfServiceLibrary
{
// NOTE: If you change the interface name "ITestService" here, you must also update the reference to "ITestService" in App.config.
[ServiceContract]
public interface ITestService
{
[OperationContract]
string GetData();
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
}
In ServiceTest.cs file code replace with below code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace MyWcfServiceLibrary
{
// NOTE: If you change the class name "TestService" here, you must also update the reference to "TestService" in App.config.
public class TestService : ITestService
{
public string GetData()
{
return string.Format("You entered: {0}", "Helloworld");
}
}
}
Step 4 ). In App.config file replace wsHttBinding with basicHttpBinding
<?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 behaviorConfiguration="MyWcfServiceLibrary.TestServiceBehavior"
name="MyWcfServiceLibrary.TestService">
<endpoint address="" binding="basicHttpBinding" contract="MyWcfServiceLibrary.ITestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/MyWcfServiceLibrary/TestService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyWcfServiceLibrary.TestServiceBehavior">
<!-- 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>
Now Press F5 for Test Wcf service with Wcf Test Client

Note : For testing wcf service with wcf test client, you have to run vs.net as administrator.
Step 5). Now add New silverlight Application in WcfLinq Solutin. Name it SilverlighTestApp.

You can see in solution explorer , it created two project one is SilverlightTestApp with Mainpage.Xaml and second is SilverlightTestApp.web with two test page .
SilverlightTestApp.Web is hosting our Wcf Service.
Step 6). Add reference of MyWcfServiceLibrary to SilvertlightApp.web

Step 7). Step 8). For create .svc file in silverlightTestApp.web ,right click on it select Add->New Item .
Select Text file template and replace its Name with MyService.svc.

Add this code to MyService.Svc without double quot
“<%@ServiceHost Language="C#" Debug="true" Service="MyWcfServiceLibrary.TestService" %>"
Add below code to Web.config file
<system.serviceModel>
<services>
<service name ="MyWcfServiceLibrary.TestService"
behaviorConfiguration="MyWcfServiceLibrary.TestServiceBehavior">
<endpoint address =""
binding ="basicHttpBinding"
contract ="MyWcfServiceLibrary.ITestService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyWcfServiceLibrary.TestServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Now set SilverlightTestAPP.web as startup project and MyService.Svc as Startp page then press F5 for testing service run or not. Service is runing then you can see the output page as below

Step 8). Add service referance in SilverlightTestApp project by right click on SilverlightTestApp , select add service referance. Add referance of MyService.svc .

It will create ServiceReferences.ClientConfig file ,it looks like
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None">
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49403/MyService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService" contract="ServiceRef.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
</system.serviceModel>
</configuration>
Step 9). Add one textbox to Mainpage.xaml.
<Grid x:Name="LayoutRoot">
<TextBox x:Name="txtDisplay" Height="25" Width="200"></TextBox>
</Grid>
Write below code in Mainpage.xmal.cs for receive data from Service.
using SilverlightTestApp.ServiceRef;
namespace SilverlightTestApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
TestServiceClient tc = new TestServiceClient();
tc.GetDataCompleted +=new EventHandler
tc.GetDataAsync();
}
void tc_GetDataCompleted(object sender, GetDataCompletedEventArgs e)
{
txtDisplay.Text = e.Result;
}
}
}
Set SilverlightTestAppTestPage.aspx as startup page and press F5.
