Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
CSS
Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no
 endpoint listening at http://192.168.1.106/WebSite/WcfServiceLibrary1/PairArithmeticService 
 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:
C#
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.
Posted
Comments
Kornfeld Eliyahu Peter 26-Apr-15 13:09pm    
How your WCF service hosted?
BugRaptor 26-Apr-15 13:25pm    
I simply published it from VS to my iis 8 Web Site.
Rajat_RJT 28-Apr-15 1:08am    
There may be some issue with your base address you provided in app.config of wcflibrary1
BugRaptor 28-Apr-15 15:52pm    
Thank you for your answer.

I finally solved the communication issue by the following corrections:

1) On the Client side, my App.config file refered a wrong endpoint address.

2) On the server side I published the WCFServiceLibrary1 on http://localhost, I had to publish it in the refered /WebSite folder: http://localhost/WebSite

3) After these fixes, I didn't got the EndpointNotFoundException anymore, but I got a ProtocolException Unhandled, (405) Method not allowed when the Client tried to invoke a WCF service method.
I finally found this was due to a configuration issue in my .Net 4.5 platform: The HTTP Activation feature was not enabled !
Now the WCF calls finally work properly.
Thank you for your help.

1 solution

I finally solved the communication issue by the following corrections:

1) On the Client side, my App.config file refered a wrong endpoint address. Here is the correct App.config content:

<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.svc">
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPairArithmeticService"
                contract="ServiceReference1.IPairArithmeticService" name="BasicHttpBinding_IPairArithmeticService" />
        </endpoint></client>
    </system.servicemodel>
</configuration>


2) On the server side I published the WCFServiceLibrary1 on http://localhost, I had to publish it in the refered /WebSite folder: http://localhost/WebSite

3) After these fixes, I didn't got the EndpointNotFoundException anymore, but I got a ProtocolException Unhandled, (405) Method not allowed when the Client tried to invoke a WCF service method.
I finally found this was due to a configuration issue in my .Net 4.5 platform: The HTTP Activation feature was not enabled !
Now the WCF calls finally work properly.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900