【问题标题】:Unable to host contract because multiple operations have the same action无法托管合约,因为多个操作具有相同的操作
【发布时间】:2014-01-04 07:38:00
【问题描述】:

我正在使用 svcutil 使用预定义的 wsdl:

svcutil some_service.wsdl

我们正在使用它来设置一个模拟服务器来测试客户端。

生成的代码如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://LIB-Operations/interfaces/ServiceResponse", ConfigurationName = "ServiceResponse")]
public interface ServiceInterface
{
    [System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action="")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    void Operation1(OperationRequest1 request);

    [System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action="")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    void Operation2(OperationRequest2 request); 
}

这会导致以下异常:

System.InvalidOperationException: The operations Operation1 and Operation2 have the same action ().  Every operation must have a unique action value.

如果我删除

Action=""

我收到以下异常:

System.ServiceModel.ProtocolException: The one-way operation returned a fault message.  The reason for the fault was 'The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).'.

请注意,如果合约中只有一个操作,则没有问题。这只是在服务器中使用时的问题,在客户端中使用生成的代码时没有问题。

处理这种情况的正确方法是什么?我不能修改客户端(它必须由svcutil生成的未修改代码支持),但可以修改我们模拟服务器中使用的svcutil生成的代码。

【问题讨论】:

    标签: c# wcf wsdl svcutil.exe


    【解决方案1】:

    Action 旨在过滤服务器端的传入请求。在这里,您的两个操作或方法,即 operation1 和 operation2 都将(OperationRequest 请求)相同的对象作为输入。因此,您的服务器将检查请求消息的 Action 属性,以确定它应该为传入请求调用哪个操作。

    这是你的答案。

    WSDL first WCF server where client does not send SOAPAction

    编辑:

    如果你不能编辑你的客户端,那么在模拟服务器中你可以尝试删除soapDocumentMethod属性中的Action属性。它必须设置为soapDocumentMethod[Action="",OneWay=value]这样的东西,删除Action部分并尝试要重新生成您的客户端,让我们看看它是否有效。

    【讨论】:

    • 是的,这是个问题,但不是我的问题。我在问题中编辑了我的示例操作以消除该问题。我不确定我的实际问题是否相关。
    • 嗨,丹佛,您的问题解决了吗?我已经编辑了答案。
    • 答案中的描述与我面临的问题不同,但是链接问题的答案是正确的。应用 MS 代码示例中的 DispatchByBodyBehaviorAttribute 解决了我的问题。我会将此标记为正确答案。
    猜你喜欢
    • 2021-02-28
    • 2021-06-21
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多