1. Create your Contract

We're using a very basic contract for this example:
    [ServiceContract(Namespace = "urn:WcfFlashRemoting:Examples:Example1")]
    public interface IHelloWorldContract
    {
        [OperationContract]
        string HelloWorld();
    }

In our example projects we actually split out the Contract from the Implementation in two separate DLLs, but this isn't necessary. We made the interface public as a result.

2. Implement your Contract

A simple contract leads to a simple service implementation:
    [ServiceBehavior(Namespace = "urn:WcfFlashRemoting:Examples:Example1")]
    class HelloWorldService : Contract.IHelloWorldContract
    {
        public string HelloWorld()
        {
            return "Hello, World!";
        }
    }

Notice that you don't need to declare this class public for WCF.

3. Create your Web Project (using ASP.Net Development Server)

4. Add a reference to your implementation and to WcfFlashRemoting

5. Set up your Service (using ASP.Net Development Server)

Your service file only needs a ServiceHost directive that includes a reference to your implementation class:
<%@ ServiceHost Language="C#" Debug="true" Service="WcfFlashRemoting.Example1.Implementation.HelloWorldService, WcfFlashRemoting.Example1.Implementation" %>

6. Modify your web.config

First, add the amf extension elements to your web config. It should look something like this when you're done:
<configuration>
  <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="amfExtensions" type="WcfFlashRemoting.ServiceModel.Configuration.AmfEnablingElement, WcfFlashRemoting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </behaviorExtensions>
      <bindingElementExtensions>
        <add name="amfMessageEncoding" type="WcfFlashRemoting.ServiceModel.Configuration.AmfBindingElementExtensionElement, WcfFlashRemoting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </bindingElementExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="amfBehave">
          <amfExtensions />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="amfBinding">
          <amfMessageEncoding />
          <httpTransport manualAddressing="true" />
        </binding>
      </customBinding>
    </bindings>

    ...
  </system.serviceModel>
</configuration>

Make sure you leave the serviceBehaviors element for your existing services. Then, for each service you want to enable amf for, add the amf endpoint. It should look something like this when you're done:
<services>
      <service behaviorConfiguration="ServiceBehavior" name="WcfFlashRemoting.Example1.Implementation.HelloWorldService">
        <endpoint
          address=""
          binding="basicHttpBinding"
          contract="WcfFlashRemoting.Example1.Contract.IHelloWorldContract"
          bindingNamespace="urn:WcfFlashRemoting:Examples:Example1"
          />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="amf"
          behaviorConfiguration="amfBehave"
          binding="customBinding"
          bindingConfiguration="amfBinding"
          bindingNamespace="urn:WcfFlashRemoting:Examples:Example1"
          contract="WcfFlashRemoting.Example1.Contract.IHelloWorldContract"
          />
      </service>
    </services>

The AMF binding needs both the bindingConfiguration and the behaviorConfiguration. Remember to add the bindingNamespace attributes based on your implementation/contract to both the standard binding and to the amf binding to ensure the wsdl does not include the tempuri namespace.

7. Create your Client

C# Client

1. Create your Client Project

2. Add a reference to WcfFlashRemoting

3. Add the Service Reference

4. Modify your app.config

Since the "Add Service Reference" dialog does not know about AMF, it screws up some of the bindings for you. To correct your app.config:

5. Strip out the binding with the textMessageEncoding element the customBinding element.

6. Add in the amf extensions just like with the server config above

7. Modify the endpoint with /amf in the address - the set behaviorConfiguration to "amfBehave" and set bindingConfiguration to "amfBinding"

8. Call your service

    class Program
    {
        static void Main(string[] args)
        {
            Example1Service.IHelloWorldContract svc = new Example1Service.HelloWorldContractClient("AmfBinding_IHelloWorldContract");
            Console.WriteLine(svc.HelloWorld());
            Console.ReadKey();
        }
    }

Last edited Oct 20, 2009 at 9:35 PM by mdekrey, version 2

Comments

No comments yet.