Service Endpoint:

February, 2008

Feb 29 2008   8:16PM GMT

Managed Services Engine



Posted by: Dilip Krishnan
SOA, WCF, Development, Web services

I’ve been playing around with the Managed services engine
In addition to being a design time  governance tool, it also doubles up as a service virtualization engine. I only mention design-time governance because the run-time aspects are not comprehensive out of the box; but with the extensible architecture of WCF its only a matter of adding new policies to the deployed services.

The tool has a nice story around versioning aswell. So far I really like it.

Managed Services Engine

Feb 28 2008   3:46AM GMT

Creating generic contracts for RESTful endpoints Part 3



Posted by: Dilip Krishnan
SOA, Development, Web services, WCF

We saw in the last couple of posts the problems with contract definitions for RESTful applications. Now for the big reveal!

Keep in mind this only applies to the GET based service contracts. The only way I figured was to use a contract thats open ended in terms of query string parameters with a return parameter as specific or open to suite the application need.

For e.g. If we want to have a URL (http://somehost/somepath/?api_key={api_key}&list_id={list_id}&filter={filter}&last_sync={last_sync}) with n query string parameters that returns a chunk of xml one might define the contract like the example below.

[OperationContract]

[WebGet(UriTemplate=”“)]

XElement SomeGETMethod();

This particular example uses LINQ To XML for the xml but it could be the regular xml dom thats manipulation or for that matter a message contract thats a strongly typed CLR object.

Now the way to call this method would be to build up a name value collection as shown

NameValueCollection queryParams = new NameValueCollection();

queryParams.Add(”api_key“, “XYZ“);

queryParams.Add(”auth_token“, “ABC“);

queryParams.Add(”method“, “rtm.tasks.getList“);

//Optional parameters 

if (!string.IsNullOrEmpty(listId))

 queryParams.Add(”list_id“, listId);

if (!string.IsNullOrEmpty(filter))

 queryParams.Add(”filter“,filter);

Use a url template and bind by name

UriTemplate uriTemplate = new UriTemplate("somepath/?api_key={api_key}&list_id={list_id}&filter={filter}&

last_sync={last_sync}");

Uri endpointAddress = uriTemplate.BindByName(new Uri(http://somehost/), queryParams)

And finally create the channel using the endpoint address and fire those requests away!!

public T GetServiceClient(Uri endpointUri)

{

WebChannelFactory<T> channelFactory = new WebChannelFactory<T>();

channelFactory.Endpoint.Binding = new WebHttpBinding();

channelFactory.Endpoint.Address = new EndpointAddress(endpointUri);

channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());

return channelFactory.CreateChannel();

}

Where T represents the service contract that we defined with the the generic operation contract

Technorati tags: , , ,


Feb 25 2008   5:54PM GMT

Weekly crumbs #8



Posted by: Dilip Krishnan
SOA, Architecture, Development, Web services, WCF

WCF

Embedding Arbitrary XML in Faults
The Tao of Authentication (Part I)
Distributed cache for the CLR

Architecture

IoC and the Unity Application Block
Understanding IoC Container
Building an N-Layer ASP.NET Application with LINQ, Lambdas and Stored Procedures

Architecting LINQ To SQL Applications, part 5
From CRUD to Domain-Driven Fluency
Advanced Messaging with a dash of DDD

Interesting
Visual LINQ: Watch query expressions as they happen!


Feb 21 2008   5:53AM GMT

Creating generic contracts for RESTful endpoints Part 2



Posted by: Dilip Krishnan
Development, Web services, WCF

Continuing from the previous post lets look at how we can define a contract that can effectively handle optional query parameters.

The easiest (not necessarily the most efficient way, more on that in a moment) is to create overloads of the GetList (example from previous post) method for each of the combination of the optional parameters that can either be present or otherwise.

Lets say we have a method with 2 parameters that are optional the service contract would have operations that look like so (just the method signatures for brevity)

RetVal Method(param1, param2)

RetVal Method(param1)

RetVal Method(param2)

RetVal Method()

The more the optional parameters the exponential the number of overloads. Thats not all WCF will not allow the same method name for overloads. The way to get around that is to set the Name property of the OperationContract to a different value, needless to say the amount of testing that might be involved in creating something like this. So how do we solve the overload problem?

The answer is defining a universal contract for RESTful web services. Next time we’ll see how to do that


Feb 21 2008   4:38AM GMT

Creating generic contracts for RESTful endpoints



Posted by: Dilip Krishnan
Development, Web services, WCF

Writing applications that use API’s from Web 2.0 applications is the rage. One such Web 2.0 application I really love is

Remember The Milk

Lets look at one of the API’s available, the “rtm.tasks.getList” method. As per the documentation one can see that it has the following properties

api_key (Required)
Your API application key. See here for more details.
list_id (Optional)
The id of the list to perform an action on.
filter (Optional)
If specified, only tasks matching the desired criteria are returned. See here for more details.
last_sync (Optional)
An ISO 8601 formatted time value. If last_sync is provided, only tasks modified since last_sync will be returned, and each element will have an attribute, current, equal to last_sync.

The it contains 4 properties 3 of which are optional… If we were to model UriTemplates for this scenario it would take one that looks like so

“somepath/?api_key={api_key}&list_id={list_id}&filter={filter}&last_sync={last_sync}”

and the OperationContract would look like this

[OperationContract]
[WebGet(UriTemplate = "path/?list_id={listId}&filter={filter}&api_key={apiKey}&last_sync={lastSync}“, BodyStyle = WebMessageBodyStyle.Bare)]
XElement GetList(string apiKey, string listId, string filter, string lastSync);

So far so good? Not so fast! The problem comes in when the service expects that the optional parameters NOT be part of the query string if the parameter is optional and empty.

i.e. if last_sync property is not supplied the service expects the url to be like so

http://someuri.org/somepath/?api_key=12345&list_id=12345&filter=somefilter

as opposed to

http://someuri.org/somepath/?api_key=12345&list_id=12345&filter=somefilter&last_sync=

Next time we’ll look at how to solve that problem

Technorati tags: ,


Feb 20 2008   11:13PM GMT

Binding to a UriTemplate



Posted by: Dilip Krishnan
Development, Web services, WCF

UPDATE: Unfortunately the formatting is messed up for a clearer formatting please visit http://dilipkrish.blogspot.com/2008/02/binding-to-uritemplate.html

The UriTemplate is pretty useful especially if we have a bunch of urls that are structurally the same.

string SomeUriTemplate = “folder/?a={a}&b={b}&c={c}“;

UriTemplate uriTemplate = new UriTemplate(SomeUriTemplate);

NameValueCollection nvc = new NameValueCollection();
After than initial setup... Lets look at the BindByPosition. Here the values supplied bind to the uri by ordinal.
Uri result = uriTemplate.BindByPosition(new Uri(”http://tempuri.org“), “1“, “2“, “3“);

Console.WriteLine(result.AbsoluteUri);

OUTPUT : http://tempuri.org/folder/?a=1&b=2&c=3
Great if the positions of the parameters dont change and also the number of parameters expected is always the same. So if we supply too many or too few parameters then we get a run time exception. Or if the template changes to "folder/?a={a}&c={c}&b={b}” we’ll start to see unexpected results!!
Uri result = uriTemplate.BindByPosition(new Uri(”http://tempuri.org“), “1“, “2“, “3“, “4“); Console.WriteLine(result.AbsoluteUri); //<- RUNTIME ERROR
The other option we have is the BindByName. Lets take a look at the following example
nvc.Add("a“, “1“);

nvc.Add(”b“, “2“);

nvc.Add(”c“, “3“);

result = uriTemplate.BindByName(new Uri(”http://tempuri.org“), nvc);

Console.WriteLine(result.AbsoluteUri);
OUTPUT : http://tempuri.org/folder/?a=1&b=2&c=3
Works as expected
nvc = new NameValueCollection();

nvc.Add(”a“, “1“);

nvc.Add(”b“, “2“);

result = uriTemplate.BindByName(new Uri(”http://tempuri.org“), nvc);

Console.WriteLine(result.AbsoluteUri);
OUTPUT : http://tempuri.org/folder/?a=1&b=2
Interesting!! it only substitutes what it knows about and leaves out the parameter c!
nvc = new NameValueCollection();

nvc.Add(”a“, “1“);

nvc.Add(”d“, “4“);

result = uriTemplate.BindByName(new Uri(”http://tempuri.org“), nvc);

Console.WriteLine(result.AbsoluteUri);
OUTPUT : http://tempuri.org/folder/?a=1&d=4
And if the NameValueCollection contains additional parameters the template does not know about it adds it to the uri when it binds to the template.


Feb 19 2008   4:09AM GMT

Weekly crumbs #7



Posted by: Dilip Krishnan
SOA

WCF
Workflow Services Context
Be careful with ServiceAuthorizationManager.CheckAccess()
C# generics - parameter variance, its constraints and how it affects WCF

Introduction to WCF Extensibility article published at LevelExtreme Magazine

Architecture
LINQ to SQL In Disconnected/N-Tier scenarios: Saving an Object

Interesting
Human LINQ

Technorati tags :


Feb 13 2008   4:25AM GMT

SOA, Enterprise Architecture, BPM all the same underneath?



Posted by: Dilip Krishnan
Development, SOA

In this article Joe McKendrick suggests that SOA EA BPM are all the same. Well, this is how I see it… EA is the goal, SOA is one of the means to it, in terms of architectural style, and BPM is a means to logically think of an SOA in any business. So, there IS a difference between them. The difference is the “View” i.e. the context, that each of them applies.


Feb 13 2008   4:08AM GMT

SOA talent and big consultancies



Posted by: Dilip Krishnan
SOA, Development

There is a meme I keep running into these days about SOA, its adoption and how it relates to consultancies.. big or small. David Linthicum has a podcast on how to choose an SOA consultancy and he lays out some common sense advice on how to pick a good consultancy. He also backs it up with an post alluding to an article which suggests

  • 56% respondents say a lack of SOA skills is “the #1 Inhibitor” to launching and delivering SOA projects with strong business impact
  • About half of all respondents admit they have less than 25% of SOA skills they deem necessary to meet long term goals
  • 80% of respondents will invest to increase SOA skills in their company this year
  • More than 60% of corporate executives invested in SOA-targeted retraining for both IT and Business staffs in the past year
  • Well IMHO that survey seems to have been worded incorrectly. For starters I dont believe retraining is required for visualizing an SOA!! All it needs is experience which is in abundance if anyone cared to look at failed EAI efforts in the past. I believe what the survey wanted to say was lack of tools/ technology skills to “IMPLEMENT” a service oriented vision!

    Like Linthicum says  to paraphrase (emphasis mine),

    Invest in collaborate with the business stakeholder, analyze and create requirements and pick a solution that apropriately satisfies your need. Then pick a vendor who can implement the solution.

    As Anne puts it succinctly

    Steve is, of course, speaking as an employee of a big consultancy. ;-)
    Nonetheless, I agree with him. Partnering with a consultancy that has
    partnerships with *many* vendors is a better idea than partnering with
    a consultancy that has *few* vendor partnerships.


    Feb 11 2008   7:06PM GMT

    Weekly crumbs #6



    Posted by: Dilip Krishnan
    Development, SOA, Web services, WCF

    Microsoft
    A gentle geek introduction to Volta
    UserName SupportingToken in WCF
    Xaml Serialization with WCF [via Rob Relyea]

    Architecture
    Data access and the enterprise architect :)

    Misc
    Windows Workflow Foundation Tutorial Series