Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client wsHttpBinding to CustomBindings in .Net 5.0 #4483

Closed
Benjiinator opened this issue Jan 6, 2021 · 5 comments
Closed

Client wsHttpBinding to CustomBindings in .Net 5.0 #4483

Benjiinator opened this issue Jan 6, 2021 · 5 comments
Assignees

Comments

@Benjiinator
Copy link

Benjiinator commented Jan 6, 2021

I'm in the middle of migrating a .Net framework client application to .Net 5.0.

I want to make a .Net 5.0 WCF client that works with our production .Net framework WCF service (wsHttpBinding)
It appears that wsHttpBindings are not supported since .Net Core, however i have found similar issues (#31) claiming to be able replace them with customHttpBindings but i have been unable to get it working.

When i attempt connecting with my current setup i get the error:
An error occurred while sending the request. with the inner exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..

My current attempt at a binding on a .Net 5.0 client:

var binding = new CustomBinding
            {
                Elements = { new HttpsTransportBindingElement //or HttpsTransportBindingElement for https:
                {
                    MaxBufferSize = 104857600,
                    MaxReceivedMessageSize = 104857600
                    
                }}
            };

Binding on our production WCF service:

<wsHttpBinding>
     <binding name="DRSchoolSyncBinding" receiveTimeout="00:02:00" sendTimeout="00:02:00" maxReceivedMessageSize="104857600">
       <security mode="Transport">
         <transport clientCredentialType="None" />
       </security>
     </binding>
</wsHttpBinding>

So my question is, how do i make a binding that works with the wsHttpBinding in .Net 5.0?

@Benjiinator Benjiinator changed the title Ws Client wsHttpBinding to CustomBindings in .Net 5.0 Jan 6, 2021
@mconnew
Copy link
Member

mconnew commented Jan 8, 2021

We do support WSHttpBinding, but not every feature available through that binding is supported. The binding config for your server side isn't using any of those features so should work without a problem. You should be able to use:

var binding = new WSHttpBinding(SecurityMode.Transport);
binding.MaxReceivedMessageSize = 104857600 };
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

@Benjiinator
Copy link
Author

@mconnew Thanks for replying!
When attempting with this binding i get the following error:
A reply message was received for operation 'MyMethodName' with action 'http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault'. However, your client code requires action 'https://www.*.com/services/ISchoolSync/MyMethodNameResponse'.

I was unable to find much about this issue on google. Any idea what to do now?

@Benjiinator
Copy link
Author

@mconnew It seems my endpoints that does not use custom bindings does work with your suggestion.
However i do have a few much needed endpoints that do use custom endpoint behavior, they trigger the error mentioned above - is it possible to use custom endpoint behavior in .Net 5.0? - this all worked in .Net framework.

My client looks like this when configured for the behavior:

var client = new ServiceClient(binding, address);
client.Endpoint.EndpointBehaviors.Add(new CustomMessageLayer());

@mconnew
Copy link
Member

mconnew commented Jan 8, 2021

That code to add a behavior should work. We support adding behaviors to the client.
I'm surprised you couldn't find anything about that error message as it's a simple enough issue. Every SOAP message has an Action header which basically says what method/operation the message is for. It looks like you have set the ReplyAction property on your OperationContract attribute to be https://www.*.com/services/ISchoolSync/MyMethodNameResponse. When a Fault message is returned by the server, that has a different Action listed, which means it doesn't match your expected ReplyAction. WCF has code to detect the message is a Fault message and will convert it to a FaultException where you can get the server side error. This depends on the Message.IsFault property. The error you are getting is caused by a Message object which represents a Fault, but the IsFault property is returning false so it treats it like a regular reply message, but then the action isn't matching. My best guess is that your custom behavior is replacing the Message object with another message object and that one you return from your extensibility is incorrectly returning IsFault=false. I recommend in whatever extensibility you have, checking the IsFault property and leaving the message unmodified if it is a fault.

@Benjiinator
Copy link
Author

@mconnew I was unable to get custom endpoint behavior working and decided to replace the 2 wcf calls i had that used it.
Closing the issue as i'm past it, thanks for the help though - it is greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants