WCF - 泛化操作字符串

发布于 2024-11-03 08:15:19 字数 1499 浏览 1 评论 0原文

我必须采用一些预定义的 WSDL(我不控制这些),并将它们公开在我们的设备上以回复各种 SOAP/UPnP 请求。

不管怎样,我已经完成了所有这些工作,但是问题出现了,因为我有一项可以在任意数量的渠道上请求的服务。我将解释:

[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);
}

基本上,我试图做的(我意识到这个语法是完全错误的,但我认为它会明白这一点)是这样的:

[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);
}

我只是想将原始操作消息的某些部分作为我正在实现的方法的参数。

我想到的唯一可以实现此目的的其他方法是指定其他方法,我们将其称为带有 Action="*" 的 Dispatcher,然后使用 OperationContext.Current 手动解析接收到的操作.IncomingMessageHeaders.Action。这似乎是一种非常阴暗的做事方式。我确信这里的主要障碍是我对 WCF 缺乏经验。

我们将非常感谢您能够提供的任何帮助。

谢谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡大本事 2024-11-10 08:15:19

管理此问题的最简单方法是创建通用消息处理程序。合同看起来像这样:

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

这个想法是为您的服务创建一个“路由器”方法 沿着本文的思路。 您仍然需要创建单独的渠道服务合同来塑造要接收和发送的肥皂消息。返回,但您将让客户端端点转到您的“路由器”服务端点。如果您为每个通道服务契约创建一个单独的实例,则可以使用新的 WCF 4 RoutingService 执行这些操作。

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.

错々过的事 2024-11-10 08:15:19

操作方法的唯一泛化是通配符 *,它通常作为通用 Message 与输入和输出一起使用。

有一种方法可以自定义操作选择以及参数定义和填充的整个行为。您可以检查以下接口:

  • IDispatchOperationSelector 用于根据传入的数据选择操作
  • IOperationInvoker 用于分配参数并调用 IDispatchOperationSelector 选择的操作
  • IDispatchMessageFormatter 用于将操作参数填充到由 IOperationInvoker 准备的分配槽中。

您可能不需要全部实现,但是它们将允许您以任何您需要的方式自定义行为。有关自定义选择器和格式化程序的示例,请查看 MSDN 示例,了解自定义调用程序的示例查看这篇文章。无论如何,整个基础设施编码只会将您的 Action 解析移动到某些 WCF 内部,但您仍然需要这样做才能将其作为操作参数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文