2

我有一个在不同环境中运行的简单 WCF 服务。今天我尝试在我的 Windows 7 工作站上运行它,并在我的客户端(这是用于测试的简单控制台应用程序)上收到此错误:

System.ServiceModel.ProtocolException:传入事务无法反序列化。消息中的事务标头格式错误或格式无法识别。客户端和服务必须配置为使用相同的协议和协议版本。发生以下异常:与底层事务管理器的通信失败。

Server stack trace: 
    at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    at ConsoleApplication1.ServiceReference1.ILookupService.GetMaritalStatus()
    at ConsoleApplication1.ServiceReference1.LookupServiceClient.GetMaritalStatus() in D:\\Temp\\ConsoleApplication1\\ConsoleApplication1\\Service References\\ServiceReference1\\Reference.cs:line 46975
    at ConsoleApplication1.Program.Main(String[] args) in D:\\Temp\\ConsoleApplication1\\ConsoleApplication1\\Program.cs:line 24

如果我更改客户端上的端点以从任何其他环境调用相同的服务 - 它工作得很好。我确定我的工作站有问题,但无法弄清楚那是什么。IIS 中的所有设置都与其他服务器上的相同。其他服务在工作站上运行良好。

服务合同如下所示:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    [TransactionFlow(TransactionFlowOption.Allowed)]
    [FaultContract(typeof(ServiceFault))]
    Result MethodName(Guid id);        
}

执行:

[ServiceBehavior(Name = "MyService", InstanceContextMode = InstanceContextMode.PerCall)]
public class MyService : IMyService
{
    public Result MethodName(Guid id)
    {
        ...
    }
}

我还没有创建这个服务,不知道为什么我们可能需要 TransactionFlow 属性。是不是这个问题。我该如何解决?

Fiddler 显示了以下响应。没有什么能帮上忙的。

HTTP/1.1 500 Internal Server Error
Content-Length: 905
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 08 Jan 2014 18:45:33 GMT

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/transactions/fault</a:Action></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Sender</s:Value><s:Subcode><s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/transactions">a:TransactionHeaderMalformed</s:Value></s:Subcode></s:Code><s:Reason><s:Text xml:lang="en-US">The incoming transaction cannot be deserialized. The transaction header in the message was either malformed or in an unrecognized format. The client and the service must be configured to use the same protocol and protocol version. The following exception occurred: Communication with the underlying transaction manager has failed.</s:Text></s:Reason></s:Fault></s:Body></s:Envelope>
4

1 回答 1

2

看起来 MSDTC 安全设置已被 Windows 更新重置。我在 Windows 日志中发现了以下日志条目:

MSDTC encountered an error (HR=0x80000171) while attempting to establish a secure connection with system <HostName>.

所以我做了两件事:

1) 授予 msdtc.log 的 NetworkServices 的完全访问权限:

icacls c:\windows\system32\msdtc\msdtc.log /grant "networkservice":F 

2) 更改本地 DTC 的安全设置(控制面板 -> 管理工具 -> 组件服务 -> 我的电脑 -> 分布式事务协调器 -> 本地 DTC -> 属性)。我设置了以下内容(根本没有设置):

本地 DTC 属性 -> 安全

于 2014-01-08T19:26:21.683 回答