Exposing multiple services as a single service

Topics: Technical Questions, Usage Scenarios
Mar 26, 2009 at 1:56 PM
Edited Mar 26, 2009 at 1:57 PM
Hello,

I have a scenario where:

  • There are two endpoints and both are having same contracts. 
  • These two endpoints are hosted in two different applications. Therefore service implementations are different (which we don’t care) though contracts are same. 
Can we virtualize these two endpoints as one service endpoint to outside using MSE?

Some interested party just call the service which is virtualized by MSE and hand over a message (fire and forget). Internally MSE distribute same message to two different underneath endpoints (with same contract).

Please share more details about extensibility of MSE around this area.


Mar 26, 2009 at 2:46 PM

I have implemented the scenario you describe into production. What you will need to do is:

- Import your operations from your hosted applications

- Create a new endpoint that you plan on exposing to this 3rd party 

- Assign your operations you want exposed to that endpoint

- Assign the endpoint to a runtime server

The beauty of MSE is the ability to logically group disparate services into one if need be. Hope that helps.

Mar 26, 2009 at 2:56 PM
Hello,

My requirement is slightly different. I want MSE created endpoint to expose only one operation to outside world and when some
one invoke that operation by sending a message, same message has to be sent to two service implementations underneath.
Mar 26, 2009 at 5:04 PM
If I understand your requirement correctly, you want MSE to invoke both services when the third party calls this virtual operation. I believe this is possible by creating a custom behavior / policy and attaching it to the endpoint.
Developer
Mar 26, 2009 at 5:15 PM
Sounds like you want to do something like a multicast where an incomming messages gets sent to multiple service implementations.

Check out these posts for inspiration:
http://servicesengine.codeplex.com/Thread/View.aspx?ThreadId=30181
http://servicesengine.codeplex.com/Thread/View.aspx?ThreadId=25814

The above links really talk about altering the WCF Channel Stack the MSE uses when sending a message.  In your case, this would be a bit more involved since you will want to implement your own IRequestChannel/IOutputChannel to take control of the sending of the message.  You can pass values stored in the Resource Moniker down into your implementation (the list of service implementation addresses) to determine which locations to send the message to.

hope that helps
Coordinator
Mar 26, 2009 at 7:32 PM
By default, the MSE has a one-to-one relationship between operation versions and resources and it sounds like you really want a one-to-many relationship.  As stated above, you can define your own channel to change this relationship, but that will be pretty involved and isn't something that will be well-represented by the model since the relationships will be buried in the moniker.  Another option is to define a WF or BTS resource that makes the necessary calls for you.  This would work very well if that resource turns around and also makes its calls through the MSE.  What results is a call into the MSE for operation Xv1 that resolves to a workflow that makes calls into the MSE for operation Xv2 and Xv3.  Of course these could be entirely different operations as well.  It's an added layer, but is probably a bit quicker way to get there and still maintains full visibility and manageability of the relationships.  We are looking to make this kind of relationship a bit easier to define and manage going forward, so let us know what you decide to do.
Mar 30, 2009 at 4:16 PM
Edited Mar 30, 2009 at 4:17 PM
Hi botto,

Thanks for the references. I received a sample code and altered that to get the functionality I need. As you have stated, I used an implementation of IOutputChannel
to send message to multiple end points. In my scenario MSE exposes a web service to publish messages. Once some application publishes a message, subscribers are
identified using values stored in resource moniker and publish message to all subscribers. Subscribers can be added as required by altering values in resource moniker.

I have two questions regarding MSE.

1. I noticed that MSE service client always sending message using asynchronous methods of channel. Is it by design of MSE or something we can change?
2. Does MSE use same instance of service client again and again or creating a new client for every call?

Williamo: I agree with your views. Flexibility provided via custom channel stack need to be used properly for correct purpose. The above proof of concept was done
to prove that MSE can be used to implement publisher/subscriber pattern without involvement of an external application. I like to go ahead with your suggestions. Please
elaborate more on how to define a WF or BTS resource in MSE.

Does that workflow run inside the process space of MSE or outside?


Coordinator
Mar 31, 2009 at 6:12 PM

Glad to hear you are making progress with the channel. 
1) Correct, Broker always calls the Async method of the channel. Custom channels can ‘block’ and return AsyncCallback.Iscompleted = true when they’re done processing. We have done this in custom channels when appropriate.  
2) The MSE does reuse service client instances by caching the ChannelFactory, which is the most expensive process of building a channel.

Today, the easeist way to work with a WF or BTS resources is to create a standalone component that is defined as a resource in the model, which would be run outside of the MSE.  We are working on a BTS metadata loader now which will use metadata in the BTS store to import an orchestration that can be invoked using one of the WCF bindings.  With WF, you could host the workflow in a Windows Service or IIS.  With .NET4.0, this will become much easier :)  Likewise, with .NET4.0 we can start looking at some options to run the workflow inside of the MSE process.