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

gar*_*daz 5 c# wcf web-services .net-4.0 windows-server-2008-r2

更新日志:

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

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

http://pastebin.com/LJurv0qA

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

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="CompanyCustomConfig"
             type="Company.Common.CustomConfigSections.EncryptedSomethingQuiteStrangeCredentialsSection, Company.Common"
             />
    <section name="CompanyMachineConfig"
             type="Company.Common.CustomConfigSections.MachineEnvironmentKeySection, Company.Common"
             />
  </configSections>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="sessionMethodsSoap"
                 receiveTimeout="00:10:00"
                 closeTimeout="00:10:00"
                 openTimeout="00:10:00"
                 sendTimeout="00:10:00"
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647">
          <security mode="Transport" />
        </binding>
        <binding name="sessionMethodsSoap1" />
        <binding name="recipientMethodsSoap">
          <security mode="Transport">
            <!--<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>-->
          </security>
        </binding>
        <!--<binding name="recipientMethodsSoap1" />-->
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https:test.jsp"
          binding="basicHttpBinding" bindingConfiguration="sessionMethodsSoap"
          contract="Session.sessionMethodsSoap" name="sessionMethodsSoap" />
      <endpoint address="https:test.jsp"
          binding="basicHttpBinding" bindingConfiguration="recipientMethodsSoap"
          contract="Recipient.recipientMethodsSoap" name="recipientMethodsSoap"        />
    </client>
  </system.serviceModel>
  <appSettings>
    <add key="SomethingQuiteStrangeActionsClientBaseUrlWL0280" value="http://localhost.fiddler:13298/api/ua"/>
    <add key="SomethingQuiteStrangeActionsContentTypeWL0280" value="application/json"/>
    <add key="SomethingQuiteStrangeActionsClientBaseUrlTesting" value="http://localhost:13298/api/SomethingQuiteStrangeactions"/>
    <add key="SomethingQuiteStrangeActionsContentTypeTesting" value="application/json"/>
    <add key="SomethingQuiteStrangeDetailsClientBaseUrlLocalDevelopment" value="http://localhost.fiddler:13298/api/detailsofsomething/>
    <add key="SomethingQuiteStrangeDetailsContentTypeLocalDevelopment" value="application/json"/>
    <add key="SomethingQuiteStrangeDetailsClientBaseUrlTesting" value="http://localhost:13298/api/SomethingQuiteStrangedetails"/>
    <add key="SomethingQuiteStrangeDetailsContentTypeTesting" value="application/json"/>
    <add key="LogFileDirectoryTesting" value="C"/>
    <add key="LogFileDirectoryLocalDevelopment" value="C:\LogFiles\CRM"/>
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <CompanyCustomConfig>
    <EncryptedSomethingQuiteStrangeCredentials>
      <EncryptedSomethingQuiteStrangeCredential service="ThingLocalDevelopment" SomethingQuiteStrangeName="un" password="pw"/>
    </EncryptedSomethingQuiteStrangeCredentials>
  </CompanyCustomConfig>
  <CompanyMachineConfig>
    <MachineEnvironmentKeys>
      <MachineEnvironmentKey name="DEV" environment="LocalDevelopment" />
      <MachineEnvironmentKey name="SERVER" environment="Testing" />
    </MachineEnvironmentKeys>
  </CompanyMachineConfig>
</configuration>
Run Code Online (Sandbox Code Playgroud)

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

日志文件已开始: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.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest请求,HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)at System.ServiceModel.Channels.RequestChannel在System.ServiceModel.Channels.Callnel.Call上的System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)的.Request(消息消息,TimeSpan超时)(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)中的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)上的,对象[]输出,TimeSpan超时)

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

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

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.
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

现在即使我们使用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):

在此输入图像描述

gar*_*daz 1

最后的问题是我需要在 Windows 2008 Server R2 上安装 .NET 4.5.1。尽管我的目标是 .NET 4.0。这完全解决了问题并且现在可以工作了。