Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .net核心服务引用-SOAP消息传递需要HTTP内容类型标头,但未找到任何标头_C#_Wcf_Soap_.net Core - Fatal编程技术网

C# .net核心服务引用-SOAP消息传递需要HTTP内容类型标头,但未找到任何标头

C# .net核心服务引用-SOAP消息传递需要HTTP内容类型标头,但未找到任何标头,c#,wcf,soap,.net-core,C#,Wcf,Soap,.net Core,我在使用生成的服务引用从.Net core 2.1web应用程序与WCF服务通信时遇到问题。在我的本地环境中,一切都可以正常工作,但一旦我将web应用程序部署到服务器,调用就会崩溃: System.ServiceModel.ProtocolException:HTTP内容类型标头为 SOAP消息传递需要,但找不到 服务it本身工作正常,可以在另一个基于asp.net 4.7.2的web应用程序中使用服务引用正确调用服务it 我已经尝试过的: 我为.netcore2.1.7和2.2 我尝试使用以

我在使用生成的服务引用从
.Net core 2.1
web应用程序与WCF服务通信时遇到问题。在我的本地环境中,一切都可以正常工作,但一旦我将web应用程序部署到服务器,调用就会崩溃:

System.ServiceModel.ProtocolException:HTTP内容类型标头为 SOAP消息传递需要,但找不到

服务it本身工作正常,可以在另一个基于asp.net 4.7.2的web应用程序中使用服务引用正确调用服务it

我已经尝试过的:

  • 我为
    .netcore2.1.7
    2.2
  • 我尝试使用以下命令将自定义内容类型头添加到请求中
  • 我尝试在服务器上运行Wireshark来查看请求,似乎没有任何请求离开应用程序
  • 我尝试用不同的配置发布web应用程序,但即使在自包含模式下,问题仍然存在
  • 我尝试了不同的消息版本绑定,只有代码中提供的绑定可以工作
以下是自定义绑定、客户端创建和请求执行代码:

CustomBinding result = new CustomBinding();

TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement
{
    MessageVersion = MessageVersion.Soap12WSAddressing10  // Soap11 message version causes content-type mismatch
};

result.Elements.Add(textBindingElement);

HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement
{
    AllowCookies = true,
    MaxBufferSize = int.MaxValue,
    MaxReceivedMessageSize = int.MaxValue
};

result.Elements.Add(httpBindingElement);

Client = new ServiceClient(result, new EndpointAddress(serviceUrl));




return await Client.GetServiceStatusAsync();
以下是服务引用的ConnectedService.json:

{
  "ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
  "Version": "15.0.20628.921",
  "ExtendedData": {
    "Uri": "%anonymized%/service?wsdl",
    "Namespace": "Service",
    "SelectedAccessLevelForGeneratedClass": "Public",
    "GenerateMessageContract": false,
    "ReuseTypesinReferencedAssemblies": true,
    "ReuseTypesinAllReferencedAssemblies": true,
    "CollectionTypeReference": {
      "Item1": "System.Array",
      "Item2": "System.Runtime.dll"
    },
    "DictionaryCollectionTypeReference": {
      "Item1": "System.Collections.Generic.Dictionary`2",
      "Item2": "System.Collections.dll"
    },
    "CheckedReferencedAssemblies": [],
    "InstanceId": null,
    "Name": "Service",
    "Metadata": {}
  }
}
以下是错误堆栈跟踪的相关部分:

at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
在System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult结果)
位于System.ServiceModel.Channel.ServiceChannel.SendAsyncResult.End(SendAsyncResult)
位于System.ServiceModel.Channels.ServiceChannel.EndCall(字符串操作,对象[]输出,IAsyncResult结果)
在System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.c\uu DisplayClass1\u 0.b\uu 0(IAsyncResult asyncResult)

下一步该去哪里?我已经用尽了我能找到或想到的所有可能的方法。

使用诸如wireshark或fiddler之类的嗅探器,比较http头以查看工作应用程序和非工作应用程序之间的差异。根据安装的webbrowser,网络应用程序的默认标题可能会有所不同。问题可能与cookies有关。请尝试删除工作机器中的Cookie,然后重试。它可能不起作用。主要区别在于,对服务的请求甚至没有离开服务器上的web应用程序(Wireshark只显示服务器之间的TCP ping、确认等,没有传输实际请求,因此无法对它们进行比较…)。至于cookies,我将客户端的AllowCookies属性更改为false,没有更改。移除cookies也毫无作用。至于浏览器,请求是由后端的托管服务执行的,甚至在任何用户发出任何请求之前,因此它不可能受到影响。http消息使用TCP作为传输层。TCP的最大数据报约1500字节。因此,请求/响应由1个或多个TCP数据报组成。当您进入安全状态时,会打开其他端口号。我怀疑TCP期间连接正在关闭,可能存在[FIN]在嗅探器数据中。如果没有出现ACK,TCP将发送多次。跟踪堆栈确认我怀疑的是到代理服务器的连接失败。尝试手动使用WebBrowser访问站点。通常在失败时,它将提供有关证书安装的说明。此消息应显示在TCP嗅探器数据中。感谢您的帮助回答。我将web应用程序直接部署到与被调用的WCF服务相同的服务器上,并且呼叫正在传递,因此它肯定与网络相关。我还与我们的技术支持人员进行了联系,结果如下:
Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]无法确定重定向的https端口
。所以出于某种原因,它试图使用https,即使SSL被禁用,在Startup.cs中,我同时注释掉了app.UseHsts()和app.usehttpseredirection()