Unable to consume WCF WSHttpBinding in .net core
Solution 1
I was able to make it work using a custom binding. There are also https, text, and binary binding elements that can be configured.
var binding = new CustomBinding
{
Elements = { new HttpTransportBindingElement //or HttpsTransportBindingElement for https:
{
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue
}}
};
Solution 2
WCF WSHttpBinding is not support yet in .net core 2.1. Here are the list of supported bindings in .Net core
- BasicHttpBinding
- CustomBinding
- NetHttpBinding
- NetTcpBinding
read more about supported features click here
Solution 3
I used WSHttpBinding on full framework. After migration to .net core 2.2 I faced with same problem.
Later I found that BasicHttpsBinding (it is https, not http) perfectly fits my need. I simple replaced WSHttpBinding with BasicHttpsBinding and all works fine (on windows and on linux).
Solution 4
This is a more complete answer and may help someone who is trying to call a SOAP service endpoint using .NET Core (.NET Core 2.2) and is struggling to get it working.
For the answer I'm assuming you've already added a Connected Service. If not, please refer to this Microsoft Article
The example below is using a BasicHttpBinding
with an Ntlm
Credential Type (DOMAIN\Username):
public async Task<string> ImportSalesOrder(string jsonString)
{
var binding = new BasicHttpsBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
var endpoint = new EndpointAddress(_appConfig["endpoint"]);
var client = new eCommIntegrationMgt_PortClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = _appConfig["usernam"];
client.ClientCredentials.UserName.Password = _appConfig["password"];
try
{
var result = await client.ImportSalesOrderAsync(jsonString);
return result.return_value;
}
catch (Exception)
{
throw;
}
}
_appConfig
is a global variable, which is made available via DI (Dependency Injection). You can replace them with hard-coded values if you're not making use of DI. The catch
is redundant here, but you can add your custom error handling/logging.
eCommIntegrationMgt_PortClient
is the client i.e. the Service object where all our endpoints exist.
Solution 5
Here is snippet what I used
var binding = GetCustomBinding();
private Binding GetCustomBinding()
{
CustomBinding result = new CustomBinding();
TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement();
result.Elements.Add(textBindingElement);
HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement
{
AllowCookies = true,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
AuthenticationScheme = System.Net.AuthenticationSchemes.Negotiate
};
result.Elements.Add(httpsBindingElement);
return result;
}
Niraj Bhattad
Updated on June 12, 2022Comments
-
Niraj Bhattad almost 2 years
I'am trying to move my project from .net to .net core. I was initially using WCF WSHttpBinding service in .net but I'am unable to consume the same in .net core. I tried using BasicHttpBinding to connect with WsHttpBinding on the client side, but it throws an error saying the Bindings should match on both client and server side.
Suggest how to implement WSHttpBinding on .Net Core without modifying WSHttpBindings on the client side.?
-
Niraj Bhattad over 5 yearsShould the bindings be same on both client and server side..? Because if Iam trying to connect using BasicHttpBinding or NetHttpBinding to client side which is WSHttpBinding in .net core it throws an exception "Client and server bindings are mismathced".
-
Michael Freidgeim over 4 yearsBasicHttpsBinding didn't work for me, but CustomBinding (suggested by Nicholas J. Markkula ) works.
-
Alexey Kulikov over 4 yearsI confirm what this one works for me. I porting WCF client from 4.7 framework to core 2.2
-
AussieJoe about 4 yearsDang, that didn't work for me. I got this: {"The action tempuri.org/XXXService/GetXXXList is not supported by this endpoint. Only WS-ReliableMessaging February 2005 messages are processed by this endpoint."}
-
Chestera over 2 yearsJust god bless you. EDIT: everyone you guys whoever I found in internet after this hours of struggling and whose comments and answers helped me to consume crappy .Net Framework 4.0 wcf service in net core 2.1 wep API