Consuming An Agatha Service From A Non-Agatha-Aware Client

5 commentsWritten on May 14th, 2010 by
Categories: agatha

A question that also comes up occasionally is how you can use an Agatha service from a client which isn’t aware of Agatha? Or more specifically: can an Agatha service be used from a client which has generated a proxy based on the WSDL of the Agatha service? The answer is yes :)

First of all, make sure your service exposes its metadata.  You do this in the usual WCF fashion:

    <behaviors>

      <serviceBehaviors>

        <behavior name="RequestProcessorBehavior">

          <serviceMetadata httpGetEnabled="true"/>

          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

          <serviceThrottling maxConcurrentCalls="500" maxConcurrentInstances="500"/>

        </behavior>

      </serviceBehaviors>

    </behaviors>

 

The serviceMetadata element with the httpGetEnabled=”true” attribute is the important one in the snippet above.

After that, you can simply generate a service proxy through visual studio or svcutil or whatever:

add_service_reference

Now you can write the following code to communicate with your Agatha Service Layer:

using System;

using Sample.NonAgathaAwareClient.MyAgathaService;

 

namespace Sample.NonAgathaAwareClient

{

    class Program

    {

        static void Main(string[] args)

        {

            using (var proxy = new MyAgathaService.WcfRequestProcessorClient())

            {

                var responses = proxy.ProcessRequests(new[] { new HelloWorldRequest() });

                var helloWorldResponse = (HelloWorldResponse)responses[0];

                Console.WriteLine(helloWorldResponse.Message);

                Console.Read();

            }

        }

    }

}

 

Notice that there are no Agatha-related using statements, nor is there any reference to Agatha or the assembly which contains the Request/Response types. All of the required data can be found within the WSDL and you can generate proxies for it just as you could with any other WCF service.  The client-side usage model is of course as bad as it always is with standard WCF (for more information, be sure to read: Why I Dislike Classic Or Typical WCF Usage) but if you’re willing to put up with it, then at least you can ;)

 

This also means that you should be able to generate service proxies for other platforms as well, as long as they support SOAP services.

  • http://www.cognisco.com John Kattenhorn

    Hi,

    Sorry it’s taken a while to come back to you … dev workstation gave up and finally traced it a toasted processor! Thanks for the post; exactly what i was wanting.I’m going to re-read you Why I Dislike Classic Or Typical WCF Usage paper and then come up with little model.

    Thanks again.

    John

  • http://geekswithblogs.net/abhijeetp/Default.aspx Abhijeet P

    “Notice that there are no Agatha-related using statements, nor is there any reference to Agatha or the assembly which contains the Request/Response types.”

    How does the client get a hold of the HelloWorldRequest and HelloWorldResponse types, the Agatha service’s WSDL won’t contain these type definitions would it?

  • TomC

    @Abhijeet P
    The WSDL will contain those types, because Agatha uses a “KnownTypeProvider” while initializing: http://davybrion.com/blog/2008/07/the-known-type-provider/.

  • bennyb

    How would you consume Agatha from a JavaScript client?

  • http://davybrion.com Davy Brion

    @Bennyb

    Andrew Rea submitted some patches to include JSON and JSONP support… not sure if everything regarding its usage is completed already, but there is a sample available.

    If you download the code form subversion, you can look at the Examples\Sample.ServiceLayer.JsonRestClient project… in the Views\Home\Index.aspx file, you can see some service calls being made through JavaScript

    again, not sure if everything works as expected in this mode though… but you can try :)