我正在使用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生成的代码。
答案 0 :(得分:1)
操作旨在过滤掉服务器上的传入请求。这里的两个操作或方法,即operation1和operation2,都将(OperationRequest请求)相同的对象作为输入。因此,您的服务器将检查请求消息的Action属性,以确定它应该为传入请求调用哪个操作。
这是你的答案。
WSDL first WCF server where client does not send SOAPAction
修改强>
如果您无法编辑您的客户端,那么在模拟服务器中您可以尝试删除soapDocumentMethod属性中的Action属性。它必须设置为soapDocumentMethod [Action =“”,OneWay = value]类似这样的东西,删除Action部分并尝试为了重新生成你的客户,让我们看看它是否有效。