【问题标题】:Call WCF service form Dotnet Core从 Dotnet Core 调用 WCF 服务
【发布时间】:2017-05-10 07:20:45
【问题描述】:

我正在使用带有自定义绑定的 WCF 服务,我设置了 gzip 以减少结果的长度。最近我们迁移到 .NET Core,在我在核心项目中调用我的方法后,我得到了这个错误

接收到http://www.???.com:96/TicketCache.svc/mex 的 HTTP 响应时出错。这可能是由于服务端点绑定未使用 HTTP 协议。这也可能是由于服务器中止了 HTTP 请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。

我在 wcf 中更改了我的配置并将其设置为基本绑定后,它工作正常

我搜索了很多并测试了不同的方式,但我无法回答

BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();

binaryMessageEncodingBindingElement.CompressionFormat = CompressionFormat.GZip;

HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
httpTransportBindingElement.MaxReceivedMessageSize = 65536000;
httpTransportBindingElement.MaxBufferSize = 65536000;

CustomBinding customBinding = null;
customBinding = new CustomBinding( new BindingElement[] { binaryMessageEncodingBindingElement, httpTransportBindingElement });
customBinding.OpenTimeout = TimeSpan.FromMinutes(10);
customBinding.CloseTimeout = TimeSpan.FromMinutes(10);
customBinding.ReceiveTimeout = TimeSpan.FromMinutes(20);
customBinding.SendTimeout = TimeSpan.FromMinutes(10);
customBinding.CreateBindingElements();

var factory = new ChannelFactory<customBinding, new EndpointAddress("http://www.???.com:96/TicketCache.svc/mex"));

我该如何解决这个问题?

【问题讨论】:

  • 服务是否启动并运行,是否授予防火墙访问权限?
  • 我允许防火墙中的服务并打开它

标签: c# wcf .net-core


【解决方案1】:

这是 .net core 问题,我通过安装 Visual Studio 2017 解决了这个问题。你应该卸载它,然后安装最新版本的 net core。目前是 1.1.2

【讨论】:

  • 它对我有用,但你有什么办法可以在不改变 .net 核心版本的情况下工作吗?
  • 是的,这是由于“数据合同”问题而发生的错误。但我不确定它是否会用其他解决方案修复
  • 我在其他系统上用 VS2017 和 .net core 1.1.1 测试了它,它工作正常,我很困惑
  • 经过不同的测试,我发现它与操作系统有关,它在 win 10 上运行良好,在 win 7 上出现问题,我知道为什么会发生这种情况
【解决方案2】:

将如下代码添加到 web.config

<behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
       <useRequestHeadersForMetadataAddress>
        <defaultPorts> <!— Use your own port numbers —>
           <add scheme="http" port="enter your web service port :8088" />
         </defaultPorts>
       </useRequestHeadersForMetadataAddress>
      </behavior>
    </serviceBehaviors>

【讨论】:

  • 我的问题是关于 .netCore 项目,它适用于 .netframwork 项目而不是关于我的网络服务
猜你喜欢
  • 2020-10-22
  • 1970-01-01
  • 2023-03-05
  • 2011-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
相关资源
最近更新 更多