views:

106

answers:

2

Since I'm contemplating to use WCF I thought it would be best to just follow a simple tutorial to get my feet wet.

3 hours later, I've only got one exception to show for. It won't go away.

I ruled out the app.config not being loaded. If I change: wsHttpBinding in the config to JHGHJGH it gives an error when running. However when I change the name of the contract interface, no errors are given (except the same one I'm facing for the last 3 hours)

Does anyone have an idea how to debug this? This kind of blackbox error stuff is very off-putting for me.

full exception:

Service 'WCFtest.TestService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element

(Don't you love these errors which indicate any of 16 possible things which might be wrong)

my program.cs

        ServiceHost host;
        Type serviceType = typeof(TestService);
        host = new ServiceHost(serviceType);
        host.Open();  //<---- exception is thrown here
        Console.ReadLine();

my test 'wcf service'

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace WCFtest
{
    [ServiceContract]
    public interface ITest
    {
        [OperationContract]
        double Add(double n1, double n2);
        [OperationContract]
        double Subtract(double n1, double n2);
        [OperationContract]
        double Multiply(double n1, double n2);
        [OperationContract]
        double Divide(double n1, double n2);
    }

    public class TestService : ITest
    {
        public double Add(double n1, double n2)
        {
            double result = n1 + n2;
            return result;
        }
        etc... some methods are removed for brevity
    }
}

my app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="WCFtest.testservice"
               behaviorConfiguration="testservicebehaviour">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/test"/&gt;
          </baseAddresses>
        </host>
        <endpoint address=""
              binding="wsHttpBinding"
              contract="WCFtest.ITest" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="testservicebehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
+1  A: 

It's not a case thing, is it? Your web config says;

WCFtest.testservice

but your code says

WCFtest.TestService 

So I suspect the difference in case may do something; usually, C# types are case-sensitive. I'm new to WCF, though...

Steve Cooper
+1  A: 

The "name" attribute of the element in the app.config is case sensitive.

Instead of "WCFTest.testservice", you need to specify "WCFtest.TestService" like so:

<service name="WCFtest.TestService" behaviorConfiguration="testservicebehaviour">
urig
Good catch. I thought the servicename was actually any name you'd give it. But you're saying it has to match the class which implements the service. Thanks! Amamzing how one can look for 3 hours at this, and someone else spots it in a few minutes
Toad
Happens to everyone ;). Here's an explanation for it - "The service name attribute specified in the config file functions as a lookup key for the corresponding ExchangeService.svc. It tells the hosting environment to which service this configuration belongs." [source: http://msdn.microsoft.com/en-us/library/bb332338.aspx]
urig
@urig I've gotten a bit scared though of the whole WPF experience. On the surface it is just adding a few attributes in the sourcecode. But the config, and the stuff which gets send back and forth (I sniffed it) is mindbogglingly complex. To interop it with other technologies like PHP for instance, is something I wouldn't even dare touch.
Toad
Don't give up on it just yet. It really is the only way forward to do interprocess communication in .net. The stuff that gets sent back and forth is actually SOAP which PHP can interop with and you also have lighter and friendlier REST support as well. Take it one bite at a time and soon enough you'll learn to love it for its power and flexibility. :)
urig