.net核心服务参考-SOAP消息传递需要HTTP Content-Type标头,但未找到

时间:2019-01-17 11:07:43

标签: c# wcf soap .net-core

我在使用生成的服务参考从.Net core 2.1 Web应用程序与WCF服务通信时遇到问题。 在我的本地环境中一切正常,但是将Web应用程序部署到服务器后,呼叫就会崩溃

  

System.ServiceModel.ProtocolException:HTTP Content-Type标头为   SOAP消息是必需的,但没有找到。

服务本身可以正常运行,可以使用在asp.net 4.7.2上构建的另一个Web应用程序中的服务引用来正确调用它

我已经尝试过的方法:

  • 我为.net core 2.1.72.2安装了运行时和托管
  • 我尝试使用此c# web service client: how to add custom header to request?
  • 将自定义内容类型标头添加到请求中
  • 我尝试在服务器上运行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)

下一步有什么想法吗?我已经用尽了所有可能找到或想到的方法。

0 个答案:

没有答案