April 2006 - Posts

WCF services and type names
Wed, Apr 12 2006 4:44 PM
If you get the following error message while trying to run a WCF service:

Service 'SomeServiceType' has zero application (non-infrastructure) endpoints.  This might be because no configuration file was found for your application, or because there was a problem with the type in the configuration file, or no endpoints were defined in the configuration file.

You might want to try to change your name attribute of your service (this attribute used to be called the type attribute in the pre-feb ctp's) from the assembly-included name to only the class-name. You need to do the same thing with a contract.

If you had a service called Services.Foo in an assembly called Services.dll and a contract called Services.Contracts.IFoo in an assembly called Services.Contracts.dll you will get the following service configuration:

<service name="Services.Foo">
    <endpoint
        address="http://localhost:8000/FooService"
        binding="wsHttpBinding"
        contract="Services.Contracts.IFoo" />
</service>

As you can see, the assembly names aren't mentioned. IMHO this is the right thing to do but is not quite evident becase a lot of the documentation if still pre feb-ctp. I found the solution for this problem here.

Another one of those things that kept me going for a while :-)
Flags enumeration sample
Tue, Apr 4 2006 5:42 PM
I had to wrestle a bit to get an enumeration with the FlagsAttribute working correctly today so I though I'd just share my working code as a sample for some Google juice. If you want to download the code, you can do so here. Hope this helps.


    7     [Flags]

    8     public enum HtmlParserOptions

    9     {

   10         NotifyOpeningTags = 1,

   11         NotifyClosingTags = 2,

   12         NotifyText = 4,

   13         NotifyEmptyText = 8,

   14         NotifyComments = 16,

   15         All = NotifyOpeningTags | NotifyClosingTags | NotifyText | NotifyEmptyText | NotifyComments

   16     }

   17 

   18     class Program

   19     {

   20         HtmlParserOptions options = HtmlParserOptions.NotifyText;

   21 

   22         static void Main(string[] args)

   23         {

   24             Program p = new Program();

   25             p.Run();

   26 

   27             Console.WriteLine("Press ENTER to exit");

   28             Console.ReadLine();

   29         }

   30 

   31         public void Run()

   32         {

   33             Console.WriteLine(IsOptionSet(HtmlParserOptions.NotifyOpeningTags));

   34             Console.WriteLine(IsOptionSet(HtmlParserOptions.NotifyClosingTags));

   35             Console.WriteLine(IsOptionSet(HtmlParserOptions.NotifyText));

   36             Console.WriteLine(IsOptionSet(HtmlParserOptions.NotifyEmptyText));

   37             Console.WriteLine(IsOptionSet(HtmlParserOptions.NotifyComments));

   38             Console.WriteLine(IsOptionSet(HtmlParserOptions.All));

   39         }

   40 

   41         private bool IsOptionSet(HtmlParserOptions singleOption)

   42         {

   43             return (options & singleOption) == singleOption;

   44         }

   45     }