1

I have to take some pre-defined WSDL's (I do not control these), and expose them on our device to reply to various SOAP/UPnP requests.

Anyway, I have all of this working, but the problem comes through because I have one service that could be requested on any number of channels. I'll explain:

[System.ServiceModel.ServiceContractAttribute(Namespace="urn:some:namespace:1", ConfigurationName="myInterface")]
public interface myInterface
{
    [System.ServiceModel.OperationContractAttribute(Action="urn:some:namespace:1#GetConfiguration", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [return: System.ServiceModel.MessageParameterAttribute(Name="config")]
    MyConfigurationResponse GetConfiguration(MyConfigurationRequest request);
}

Basically, what I'm attempting to do (I realize this syntax is completely wrong but I think it will get the point across) is this:

[System.ServiceModel.ServiceContractAttribute(Namespace="urn:some:namespace:{channelNumber}", ConfigurationName="myInterface")]
public interface myInterface
{
    [System.ServiceModel.OperationContractAttribute(Action="urn:some:namespace:{channelNumber}#GetConfiguration", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [return: System.ServiceModel.MessageParameterAttribute(Name="config")]
    MyConfigurationResponse GetConfiguration(MyConfigurationRequest request, String channelNumber);
}

I simply would like some portion of my original Action message passed in as a parameter to the method I'm implementing.

The only other way I have thought of that I could implement this, would be to specify some other method, we'll call it Dispatcher with the Action="*", and then manually parse the received action using OperationContext.Current.IncomingMessageHeaders.Action. This just seems like a really shady way of doing things. I'm certain that the main roadblock here is my inexperience with WCF.

Any help you're able to provide would be much appreciated.

Thanks,

ifdef_debug
  • 11
  • 1
  • 2

2 Answers2

1

The easiest way to manage this is to create a generic message handler. The contract would look something like this:

[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface ICatchAll
{
    [OperationContract(IsOneWay = false, Action = "*", ReplyAction = "*")]
    Message ProcessMessage(Message message);
}

The idea is that you create a "router" method for your service along the lines of this article. You'll still need to create the individual channel service contracts to shape the soap message to be received & returned but you'll have the client endpoint go to your "router" service endpoint. You may be able to do something along these lines with the new WCF 4 RoutingService if you create a separate instance of each channel service contract.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • Thanks for the comment Sixto. As you will soon see, I'm still starting out with this stuff. Maybe I can re-structure my question to get somewhat of a different type of solution. I don't really have a problem modifying the interface files generated by SVCUtil.exe, but I could have over 128 different channels coming through from various UPnP clients, and coding all those by hand for the 3 or 4 services would be overwhelming. – ifdef_debug Apr 21 '11 at 21:36
1

The only generalization of action method is the wild card * and it is usually used with both input and output as generic Message.

There is a way to customize whole behavior of the operation selection and parameters definition and filling. You can check following interfaces:

  • IDispatchOperationSelector is used to select operation based on incomming data
  • IOperationInvoker is used to allocate parameters and invoke the operation selected by IDispatchOperationSelector
  • IDispatchMessageFormatter is used to fill parameters for the operation to allocation slots prepared by IOperationInvoker

You probably don't need to implement them all but they will allow you to customize the behavior in any way you need. For example of custom selector and formatter check MSDN samples for example of custom invoker check this article. Anyway this whole infrastructure coding will just move your Action parsing to some WCF internals but you will still have to do that to get it as operation parameter.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • This sounds more like what I was looking for, and think it's going to eventually get me to a solution. I won't have a chance to try it out until tomorrow, but I'll update SO as well at that time. Much appreciated is what your help is. =) – ifdef_debug Apr 21 '11 at 21:53