从WCF客户端连接到服务器的问题 – HTTPS端点 – 适用于本地开发但不适用于服务器

更新日志:

  1. 添加了更多详细信息 – 包括WCF跟踪。

首先,不是很多WCF经验,所以如果这是一个明显的错误,请道歉。 我正在编写一个简单的控制台应用程序,需要连接到第三方SOAP Web服务。 供应商提供的WSDL在这里:

http://pastebin.com/LJurv0qA

我已经使用它在Visual Studio 2010(使用.NET 4.0)中创建服务引用来创建后面自动生成的代码。 我还为各种配置设置了app.config:

   
<!----> <!---->

现在在我的LocalDevelopment框(即我的笔记本电脑)上,客户端工作正常,我可以使用他们的Logon()操作连接到第三方服务。 当我将我的代码部署到我们的测试服务器时,相同的代码和配置,n会引发以下exception:

日志文件已开始:18/11/2015 20:11:25在机器TESTSERVER上================================= =========================================== 18/11/2015 20: 11 >>>> ***已记录的应用程序:登录日期:18/11/2015 20:11:25消息:客户端问题(Client.Logon()) – 通信问题 – 消息:发出HTTP请求时发生错误to test.jsp。 这可能是由于在HTTPS情况下使用HTTP.SYS未正确配置服务器证书。 这也可能是由客户端和服务器之间的安全绑定不匹配引起的。 堆栈跟踪:

服务器堆栈跟踪:在System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest request,HttpAbortReason abortReason)
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)at System.ServiceModel.Channels.RequestChannel.Request(Message message,TimeSpan timeout)at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message,TimeSpan) System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime) System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)中的操作)

在[0]处重新抛出exception:在Hachette.CRM的System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)的System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)处。 Hachette.CRM.AdobeCRMService.AdobeClient.Logon()中的AdobeCRMService.Session.sessionMethodsSoap.Logon(LogonRequest请求)位于C:\ My Documents \ Hachette.CRM \ Hachette.CRM.AdobeCRMService \ Adob​​eClient.cs:line 84other:System.Collections .ListDictionaryInternal

根据以下评论者的建议,我已在发生错误的服务器上启用了WCF跟踪。 通过通道发送消息后抛出exception

 Exception Type: System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message: The underlying connection was closed: An unexpected error occurred on a send. Exception Type: System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message: Received an unexpected EOF or 0 bytes from the transport stream. 

为清晰起见,这是一张图片:

在此处输入图像描述

现在即使我们使用HTTPS,第三方也不需要证书 – Logon()操作为我提供了稍后使用的sessionId – 所以我假设使用basicHttpBinding我没问题?

要知道的事情:

  1. 我的本地开发框运行Windows 8.1
  2. 部署到的测试服务器正在运行Windows Server2008 R2 Standard(已安装SP1)。
  3. 我的客户端是.NET 4.0 C#控制台应用程序。
  4. 尝试使用相同的WSDL失败的服务器上的SOAP UI – 请求工作并遗漏了网络,因此它必须是框中的WCF / .NET问题。
  5. 此外,WCF激活需要为像我一样使用WCF的应用程序启用 – 添加了服务引用和自动生成的代码吗? 我们关闭是因为它导致其他网站崩溃(需要服务模型3.0.0.0):

在此处输入图像描述

最后的问题是我需要在Windows 2008 Server R2上安装.NET 4.5.1。 即使我的目标是.NET 4.0。 这解决了问题的完成,现在有效。

做一些SSL故障排除。 一些选择:

  1. 快速尝试:存在Stack Overflow问题,其中包含相同的错误消息“从传输流中收到意外的EOF或0个字节” ,其中解决方案是在调用之前显式设置SSL版本:

     ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; 
  2. 启用System.Net跟踪 ,这可能会为您提供更多线索。

  3. 使用Wireshark或类似方法来嗅探SSL握手 。