WSDL 第一个 WCF 服务器,客户端不发送 SOAPAction [英] WSDL first WCF server where client does not send SOAPAction

查看:24
本文介绍了WSDL 第一个 WCF 服务器,客户端不发送 SOAPAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个 WCF Web 服务,该服务与我无法控制其代码的客户端进行交互.WSDL 由客户端提供.

I am implementing a WCF web service which interacts with a client whose code I do not control. The WSDL was supplied by the client.

我使用 SvcUtil 从 WSDL 生成 C# 文件,除了讨论的错误 这里 我没有遇到任何问题.

I generated C# files from the WSDL using SvcUtil, and besides the errors discussed here I had no issues.

在启用 SSL 的 IIS 7.0 中托管服务(客户端需要)后,我尝试让客户端向服务发出请求.

After hosting the service in IIS 7.0 with SSL enabled (required by the client) I attempted to get the client to make a request to the service.

此时我收到以下错误:

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).

我确认我可以使用服务发布的元数据和 SOAPUI 来发出相同的请求.这工作得很好.

I verified that I could use the metadata published by the service along with SOAPUI to make the same request. This worked fine.

然后我尝试使用客户端提供的 WSDL 来使用 SOAPUI.这失败了,并出现了上面相同的空操作错误.

I then attempted to use SOAPUI using the WSDL supplied with the client. This failed with the same empty action error above.

然后我连接了 Wireshark(启用 SSL 解密)并验证从客户端发送的消息确实缺少 SOAPAction,所以看起来这绝对是问题所在.

I then hooked up Wireshark (enabling SSL decryption) and verified that the message sent from the client indeed lacks a SOAPAction, so it appears that this is definitely the issue.

由于我无法更改客户端,有没有办法让 WCF Web 服务与这样的客户端进行交互?我猜它需要接受没有 SOAPAction 的请求,而是从 SOAP 信封中的请求对象类型派生所需的请求?

As I cannot change the client is there a way to get a WCF web service to interact with such a client? I'm guessing it would need to accept requests with no SOAPAction and instead derive the desired request from type of the request object in the SOAP envelope?

推荐答案

以下对我有用(基于 这个线程):

The following worked for me (based on this thread):

  1. 下载 Microsoft WCF 示例.
  2. 将以下文件从 WF_WCF_SamplesWCFExtensibilityInteropRouteByBodyCSservice 添加到您的项目中
    • DispatchByBodyOperationSelector.cs
    • DispatchByBodyBehaviorAttribute.cs
  • XmlSerializerFormat
  • DispatchByBodyBehavior

将以下内容添加到您的服务接口

Add the following to your service interface

[OperationContract(Action = "")]
public void DoNothing()
{
}

  • 对于我的服务,所有消息的 WrapperName 和 Wrappernamespace 都是 null.我必须进入 DispatchByBodyBehaviorAttribute 并编辑 ApplyDispatchBehavior() 以添加以下行来检查:

  • For my service the WrapperName and Wrappernamespace are null for all messages. I had to go into DispatchByBodyBehaviorAttribute and edit ApplyDispatchBehavior() to add the following lines to check for this:

     if (qname.IsEmpty) {
         qname = new XmlQualifiedName(operationDescription.Messages[0].Body.Parts[0].Name, operationDescription.Messages[0].Body.Parts[0].Namespace);
     }
    

  • 这篇关于WSDL 第一个 WCF 服务器,客户端不发送 SOAPAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆