none
Call WCF NetTcpContextBinding from .NET Core 2.0 RRS feed

  • Question

  • I have a .NET Core 2.0 REST-based API and need to call an external API that uses NetTcpContextBinding binding. NetTcpContextBinding is not supported with .NET Core 2.0 (source: ). I tried to create a new project targeting the full .NET framework 4.6X but I get the following error: Could not load type 'System.ServiceModel.NetTcpContextBinding' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    The System.ServiceModel, Version=4.0.0.0 DLL reference within the full .NET framework references but when I view the DLL within an object browser, it is referencing the .NET Standard DLL variant: nuget\packages\system.servicemodel.primitives\4.4.3\ref\netstandard2.0\System.ServiceModel.dll

    I cannot specify an app.config which is probably due to the fact that I am executing the call under the .NET Core 2.0 API. An option would be to create a new hosted API under .NET framework so it can run completely under the .NET Framework but I don't like the extra hop. What are my options?




    • Edited by SAgosto Thursday, July 12, 2018 1:32 PM
    Thursday, July 12, 2018 1:27 PM

All replies

  • WCF services are not supported under .NET Core at this time. Calling WCF services from .NET Core can be done by bringing in some additional dependencies. There is a blog post here on how to do that. Note that you won't have access to the IDE-generated service reference class in a .NET Core project so you'll have to build it out by hand.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, July 12, 2018 2:12 PM
    Moderator
  • WCF services are not supported under .NET Core at this time. Calling WCF services from .NET Core can be done by bringing in some additional dependencies. There is a blog post here on how to do that. Note that you won't have access to the IDE-generated service reference class in a .NET Core project so you'll have to build it out by hand.


    Michael Taylor http://www.michaeltaylorp3.net

    Correct. I am trying to call a WCF service using the NetTCpContextBinding. Is this supported? I found this post (https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v2.0.0.md) which indicates it is not supported but not sure if it is accurate. 



    • Edited by SAgosto Thursday, July 12, 2018 6:00 PM
    Thursday, July 12, 2018 3:44 PM
  • Take a look at the System.ServiceModel.NetTcp NuGet package to add in the core NetTcpBinding but it just forwards to the underlying .NET Framework so it probably won't work in a pure .NET Core app.  I don't see the context version anywhere.

    If the official repo from MS says it isn't supported yet then it likely isn't. It is still being discussed whether WCF will be ported at all to .NET Core.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, July 12, 2018 4:04 PM
    Moderator
  • Take a look at the System.ServiceModel.NetTcp NuGet package to add in the core NetTcpBinding but it just forwards to the underlying .NET Framework so it probably won't work in a pure .NET Core app.  I don't see the context version anywhere.

    If the official repo from MS says it isn't supported yet then it likely isn't. It is still being discussed whether WCF will be ported at all to .NET Core.


    Michael Taylor http://www.michaeltaylorp3.net

    Is the only other option to create a new WCF IIS Hosted application which calls the WCF service which would be called from the .NET Core REST API?

    • Edited by SAgosto Thursday, July 12, 2018 6:00 PM
    Thursday, July 12, 2018 4:33 PM
  • If you create another WCF hosted app then you're going to still be in the same boat. If the service is yours then I'd recommend you just add a supported binding to your service.

    If that isn't an option then the next step would be to create a REST API that wraps the WCF call and then use the API in your .NET Core app.

    Yet another option would be to go get the code from the binding from ReferenceSources and then try to implement it in your .NET Core code. Not sure how difficult it'll be but I suspect there is a lot of layering going on. But if the base WCF client code has already been migrated to .NET Core it would be easier.

    Finally you could just write the necessary SOAP logic yourself. It is probably going to be ugly and certainly trial and error but it isn't any different than what would happen if someone tried to call your WCF service from a non-.NET app anyway. You could probably use SoapUI or equivalent to get some starter code if needed.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, July 12, 2018 4:43 PM
    Moderator
  • If you create another WCF hosted app then you're going to still be in the same boat. If the service is yours then I'd recommend you just add a supported binding to your service.

    If that isn't an option then the next step would be to create a REST API that wraps the WCF call and then use the API in your .NET Core app.

    Yet another option would be to go get the code from the binding from ReferenceSources and then try to implement it in your .NET Core code. Not sure how difficult it'll be but I suspect there is a lot of layering going on. But if the base WCF client code has already been migrated to .NET Core it would be easier.

    Finally you could just write the necessary SOAP logic yourself. It is probably going to be ugly and certainly trial and error but it isn't any different than what would happen if someone tried to call your WCF service from a non-.NET app anyway. You could probably use SoapUI or equivalent to get some starter code if needed.


    Michael Taylor http://www.michaeltaylorp3.net

    I meant I would create a brand new IIS WCF Hosted Service that is called from the .NET Core Rest API call which would be responsible for calling the NetTCPContextBinding WCF service.  The new IIS WCF Hosted Service would run under the FULL .NET Framework stack rather than .NET Core.

    BEFORE: .NET Core Rest API -> Call NetTcpContextBindWCF service

    AFTER: .NET Core Rest API -> Call new IIS WCF WebApp with one of the .Net Core Bindings -> Call NetTcpContextBindWCF service

    • Edited by SAgosto Thursday, July 12, 2018 6:04 PM
    Thursday, July 12, 2018 6:04 PM
  • I created a POC from above and it works as expected. I don't like the additional hop but I can't see any other way if .NET Core doesn't support it.
    Thursday, July 12, 2018 7:11 PM
  • Do you own the original WCF service? If so then you can just add a new endpoint and binding in the config and forego the need for a second service. This assumes you're not actually relying on any special features in the original binding that won't work in other bindings though.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, July 12, 2018 7:32 PM
    Moderator
  • Do you own the original WCF service? If so then you can just add a new endpoint and binding in the config and forego the need for a second service. This assumes you're not actually relying on any special features in the original binding that won't work in other bindings though.

    Michael Taylor http://www.michaeltaylorp3.net


    They are using the Context for authentication within the header. They are unwilling to add additional bindings -- That would be too easy. I have a solution but hope .NET Core adds full WCF given how prevalent it is. Thank you for the help.

    Friday, July 13, 2018 1:55 PM