我在使用生成的服务参考从.Net core 2.1
Web应用程序与WCF服务通信时遇到问题。 在我的本地环境中一切正常,但是将Web应用程序部署到服务器后,呼叫就会崩溃:
System.ServiceModel.ProtocolException:HTTP Content-Type标头为 SOAP消息是必需的,但没有找到。
服务本身可以正常运行,可以使用在asp.net 4.7.2
上构建的另一个Web应用程序中的服务引用来正确调用它
我已经尝试过的方法:
.net core 2.1.7
和2.2
安装了运行时和托管这是自定义绑定,客户端创建和请求执行代码:
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)
下一步有什么想法吗?我已经用尽了所有可能找到或想到的方法。