wcf icon indicating copy to clipboard operation
wcf copied to clipboard

Why WSHttpBinding convert to CustomBinding ?

Open gzpbx opened this issue 10 years ago • 11 comments

I am using WCF Connected Service to generate the WCF client code , I see some code like this --

Why when endpointConfiguration = WSHttpBinding then create a CustomBinding, are they total compatible ?

        private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
        {
            if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IExchangeRateService))
            {
                System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
                System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
                result.Elements.Add(textBindingElement);
                System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
                httpBindingElement.AllowCookies = true;
                httpBindingElement.MaxBufferSize = int.MaxValue;
                httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
                result.Elements.Add(httpBindingElement);
                return result;
            }
            throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
        }

gzpbx avatar Jul 14 '16 07:07 gzpbx

WsHttpBinding isn't currently supported, see issue #31. They are probably not completely compatible, but I've found I can make at least basic calls to WS-* based services.

StrangeWill avatar Jul 15 '16 18:07 StrangeWill

Hi @gzpbx, as @StrangeWill explained it is because the WS* bindings are not currently supported in .NET Core. Please let us know if you run into any issues.

zhenlan avatar Jul 18 '16 23:07 zhenlan

CustomBinding code not working for me, unfortunately:

System.ServiceModel.FaultException was unhandled by user code
  HResult=-2146233088
  Message=The message could not be processed. This is most likely because the action 'http://tempuri.org/IMrsWhatService/FindTerms' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
  Source=System.Private.ServiceModel
  StackTrace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       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)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at BackgroundService.WhatServiceAdapter.<InternalFindTerms>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at BackgroundService.CortanaCanvas.<ProcessDefinitionRequest>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at BackgroundService.CortanaCanvas.<Run>d__1.MoveNext()
  InnerException: 

cc @StrangeWill

bc3tech avatar Jul 20 '16 15:07 bc3tech

Ouch, yeah you'll need to wait for WsHttpBinding support then @bc3tech :(

StrangeWill avatar Jul 20 '16 19:07 StrangeWill

@zhenlan @StrangeWill the CustomBinding working fine for me when the wcf server only support WsHttpBinding binding , I think if there is no security demand CustomBinding works fine.

gzpbx avatar Jul 23 '16 04:07 gzpbx

Hi @gzpbx -- what is the latest status on this issue? Is using a CustomBinding without asking for security an adequate workaround for you? Thanks.

roncain avatar Dec 05 '16 18:12 roncain

@roncain, it's OK for me. And our product is running online. Just weird ...

gzpbx avatar Jan 11 '17 06:01 gzpbx

Closing. Thanks for the update @gzpbx!

zhenlan avatar Jan 25 '17 07:01 zhenlan

so.... this is closed because it works now? my error above should no longer happen?

bc3tech avatar Jan 25 '17 18:01 bc3tech

Sorry for my brevity @bc3tech. Please let me explain.

This issue is about "why WSHttpBinding convert to CustomBinding" in the code generated by WCF Connected Service. The answer to that is because WSHttpBinding is currently not supported. I understand CustomBinding may not work for all scenarios as an alternative solution. To ultimately solve this issue, it requires the support of WS*Binding, which is tracked in #31. There is nothing more for this issue to track and thus closed. Does this make sense to you?

zhenlan avatar Jan 25 '17 20:01 zhenlan

Is there any workarounds? I tried creating custom bindings, but there is a mismatch between Soap 1.1 and 1.2.

viktorpeacock avatar Feb 11 '19 16:02 viktorpeacock