I tried the
A Beginner's Tutorial for Understanding Windows Communication Foundation (WCF)[
^] but got problem when trying to call the WCF service across my LAN. I hosted the WCF service on my iis server (at 192.168.1.106) and tried to call it from the client app located on the server itself or on another machine. I always get the following exception:
Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no
endpoint listening at http:
that could accept the message. This is often caused by an incorrect address or SOAP.
Here is the App.config of the WCFServiceLibrary1:
</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="WcfServiceLibrary1.PairArithmeticService">
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IPairArithmeticService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://192.168.1.106/WebSite/WcfServiceLibrary1/PairArithmeticService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
I published it succesfully on the server and got the following Web.config file in the c:\inetpub\wwwroot folder:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<compilation debug="true" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</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="WcfServiceLibrary1.PairArithmeticService">
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IPairArithmeticService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://192.168.1.106/WebSite/WcfServiceLibrary1/PairArithmeticService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
On the Client side, I added a Service Reference and got the following App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPairArithmeticService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.1.106/WebSite/WcfServiceLibrary1/PairArithmeticService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPairArithmeticService"
contract="ServiceReference1.IPairArithmeticService" name="BasicHttpBinding_IPairArithmeticService" />
</client>
</system.serviceModel>
</configuration>
Here is my WCF Client Form code:
namespace TestWcfServiceLibrary1WindowsFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
PairArithmeticServiceClient client = new PairArithmeticServiceClient();
Pair pair1 = new Pair();
Pair pair2 = new Pair();
Pair resultPair;
try
{
pair1.First = int.Parse(tbxPair1First.Text);
}
catch (FormatException)
{
tbxPair1First.Text = "0";
pair1.First = 0;
}
try
{
pair1.Second = int.Parse(tbxPair1Second.Text);
}
catch (FormatException)
{
tbxPair1Second.Text = "0";
pair1.Second = 0;
}
try
{
pair2.First = int.Parse(tbxPair2First.Text);
}
catch (FormatException)
{
tbxPair2First.Text = "0";
pair2.First = 0;
}
try
{
pair2.Second = int.Parse(tbxPair2Second.Text);
}
catch (FormatException)
{
tbxPair2Second.Text = "0";
pair2.Second = 0;
}
resultPair = client.Add(pair1, pair2);
tbxResultFirst.Text = resultPair.First.ToString();
tbxResultSecond.Text = resultPair.Second.ToString();
}
private void btnSubstract_Click(object sender, EventArgs e)
{
PairArithmeticServiceClient client = new PairArithmeticServiceClient();
Pair pair1 = new Pair();
Pair pair2 = new Pair();
Pair resultPair;
try
{
pair1.First = int.Parse(tbxPair1First.Text);
}
catch (FormatException)
{
tbxPair1First.Text = "0";
pair1.First = 0;
}
try
{
pair1.Second = int.Parse(tbxPair1Second.Text);
}
catch (FormatException)
{
tbxPair1Second.Text = "0";
pair1.Second = 0;
}
try
{
pair2.First = int.Parse(tbxPair2First.Text);
}
catch (FormatException)
{
tbxPair2First.Text = "0";
pair2.First = 0;
}
try
{
pair2.Second = int.Parse(tbxPair2Second.Text);
}
catch (FormatException)
{
tbxPair2Second.Text = "0";
pair2.Second = 0;
}
resultPair = client.Subtract(pair1, pair2);
tbxResultFirst.Text = resultPair.First.ToString();
tbxResultSecond.Text = resultPair.Second.ToString();
}
}
}
The curious thing is that I always get the EndpointNotFoundException when I run the Client from any LAN machine or even from the server itself, but when I run it from VisualStudio (Debug/StartNewInstance)
and if VisualStudio was launched as Administrator (on the server machine) I get no exception an the WCF call works properly !!! But if VisualStudio was launched normally I get the EndpointNotFoundException...
I also tried to launch my Client App as Administrator (Out of VS) but it failed too with the EndpointNotFoundException (either from the server machine or from another machine)...
Thank you for any help.