Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Calling WCF from Azure function through web relay throw error.

Open linujohn22 opened this issue 1 year ago • 1 comments

We have WCF service deployed on On Premise and it is exposed in Azure through Azure web relay (WCF). Reference :https://learn.microsoft.com/en-us/azure/azure-relay/service-bus-dotnet-hybrid-app-using-service-bus-relay This WCF is created in .Net Framework 4.7.2 version .

Our requirement is to call this WCF service from Azure function . The azure function framework is .Net7.0 .

We use below code in Azure function to call this WCF service through Web Relay.

// Define the service URL and binding string serviceUrl = "sb://URL"; // Create the channel factory // Create shared access signature token credentials for authentication. channelFactory = new ChannelFactory(new BasicHttpBinding(), new EndpointAddress(serviceUrl)); channelFactory.Endpoint.Address.Equals(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "Key") });

We add Nuget package

Microsoft Azure.service.Bus System.servicemodel.http System.servicemodel.Primitives window.azure.service

We are getting below error while executing lines Code : channelFactory.Endpoint.Address.Equals(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "Key") });

Error System.Private.CoreLib: Exception while executing function: FunWebRelayCall. AFwcfWebrelayCall: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

we are unable to find .net7 code for using TransportClientEndpointBehavior

linujohn22 avatar Jan 26 '24 17:01 linujohn22

Thanks for reporting will check and confirm the same.pls share the repro steps.and func app name.

bhagyshricompany avatar Feb 05 '24 06:02 bhagyshricompany

@linujohn22 Is this issue still existing?

Root Cause: You're building your Azure Function in .NET 7, but System.ServiceModel version 4.0.0.0 is from the .NET Framework, not compatible with .NET Core/5/6/7.

This class is not included in .NET Core or .NET 7 WCF client packages. new TransportClientEndpointBehavior(...)

steps to fix:

->Remove any reference to System.ServiceModel from .NET Framework

-> Install packages compatible with .net7 dotnet add package Microsoft.Azure.Relay --version 2.0.0 dotnet add package System.ServiceModel.Http --version 4.10.3 dotnet add package System.ServiceModel.Primitives --version 4.10.3

-> Replace Unsupported TransportClientEndpointBehavior Usage TransportClientEndpointBehavior is not available in .NET Core / .NET 7.

Instead, you must create a custom endpoint behavior or use the newer HybridConnectionClient (low-level SDK) pattern. https://learn.microsoft.com/en-us/azure/azure-relay/relay-hybrid-connections-dotnet-get-started

VineethReyya avatar Apr 21 '25 07:04 VineethReyya

We are closing this ticket due to a lack of recent activity. If the issue still persists, please feel free to open a new ticket, and we will be happy to assist you further.

Thank you for your understanding!

VineethReyya avatar Apr 23 '25 05:04 VineethReyya