Configuration

Service Helpers is designed to be easy to configure and work with. Service helpers is designed to be the glue that lives between the services in your software system. Service helpers (SH) can be used in a WCF scenario, or without WCF. Configuration of how services are hosted, and how they are consumed is easy to do.

First some rules.

1. All services could be WCF services, this isn't a requirement, but they will all act like WCF services. This means no accessing properties in your services. You also need to decorate all services with the ServiceContract attribute.

2. Configuration file rules over attributes. If an attribute and configuration file are in conflict, the configuration file wins.

3. AddProxyOverride, very useful for unit testing, rules all. It will override config or attributes.

4. If an endpoint is configured as http, service helpers will assume WS2007HttpBinding.

Configuring an in proc service

This mode of operation is a lot like using a in dependency injection framework, you basically are just hiding your class behind a contract.

The example below creates a service running in the same process. The service will be a fully hosted WCF net.pipe service.

    [ServiceContract]
    [InProc("BasicTests.MyService2, BasicTests")]
    public interface IMyService2
    {
        [OperationContract]
        string TestMe(string input);
    }

    class MyService2 : ServiceBase, IMyService2
    {
        public string TestMe(string input)
        {
            return input;
        }
    }


To call the in proc service just using the following code.

var factory = new ProxyFactory();
var proxy = factory.Proxy<IMyService>();
var result = proxy.TestMe("hi");            


If you want to change the service to be just like referencing a class (thru an interface), just set the noWcf attribute to true.

    [ServiceContract]
    [InProc("BasicTests.MyService2, BasicTests", true)]
    public interface IMyService2
    {
        [OperationContract]
        string TestMe(string input);
    }

Configure calling an http hosted service

Calling an externally hosted http service is pretty simple. Just add the service helpers configuration section to your application, then start making calls.

  <configSections>    
    <section name="ServiceHelpers" type="DontPanic.Helpers.ServiceHelpersConfigSection, DontPanic.ServiceHelpers" allowDefinition="Everywhere" allowLocation="true"/>
  </configSections>

  <ServiceHelpers>
    <external>

      <endpoint
        contract="BasicTests.ITimeoutTest"
        address="http://localhost:9595/timeouttest" 
        timeout="120" />

    </external>
  </ServiceHelpers>



Last edited Dec 21, 2011 at 3:35 AM by chadmichel, version 6

Comments

No comments yet.