Calling WCF from Azure function .Net 7.0 throw error Could not load file or assembly 'System.ServiceModel,
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<IProductsChannel>(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
Did this work using a 4.x version of the WCF Client libraries?
WCF services built in .Net framework 4.7.2 . However we haven't used 4.X version of WCF client libraries
The reason why I asked was because the 4.X version of the libraries had a type forwarding implementation of System.ServiceModel.dll which allowed using binaries compiled against .NET Framework to run on .NET. But it only works with a narrow set of scenarios. Basically if you aren't using any custom binding elements, or you have a behavior which only has a client side implementation. I suspect TransportClientEndpointBehavior wouldn't even work with the 4.X version of the libraries so I was wondering if you have a regression from an earlier .NET build or this was new usage of the nuget packages. Sounds like the latter.
You can't use libraries compiled against .NET Framework which uses WCF on .NET, that's a scenario we dropped a while ago. And as mentioned, I suspect it wouldn't have worked either. You can try the 4.X packages to see if that works, and if so, there might be a solution.
Btw, the following code doesn't make sense:
channelFactory.Endpoint.Address.Equals(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "Key") });
Did you mean channelFactory.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior .....?
I can't find the nuget package you specified, you have a space in there. If you can provide me the correct name of the nuget package which contains TransportClientEndpointBehavior I can take a quick look and see how it's implemented and if it's something you can add into your own app without a lot of difficulty. Looking for docs, it's labelled as deprecated so I don't think the owning team is going to rework it for .NET, but it might be easy to throw together something which does what you need.
Below is correct code // Create shared access signature token credentials for authentication. channelFactory = new ChannelFactory<IProductsChannel>(new NetTcpRelayBinding(), "sb://yourServiceNamespace.servicebus.windows.net/products"); channelFactory.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider( "RootManageSharedAccessKey", "yourKey") });
Nuget Package Name : WindowsAzure.ServiceBus (7.0.1)
i tried 4.x version also but issue still exist
It says that package is deprecated and says to upgrade to Azure.Messaging.ServiceBus. I had a look at that and doesn't look like it has the equivalent types. Are you certain the Azure service you are using hasn't been deprecated? It could just be this particular function in the nuget package wasn't reimplemented in the new package, or it could be it wasn't reimplemented because the service is being deprecated. If the relay service is still going to be around long term, then there might be scope for us to do something here as we are working to enable cloud attach scenarios. The work I did to release NetNamedPipe enabled more easily building alternative transports like this. The package you are using has a lot of code copied from WCF .NET Framework, a lot of which wouldn't be needed now with a .NET port.
I can confirm there's no way this package will ever work as-is used against the .NET WCF Client packages, even if we brought back the type forwarding compat facade. It has dependency on server APIs which will never be released.
So the first step is to determine if the Azure relay service is staying around, and then go from there.
Close this issue as it has been a while. Feel free to re-open if the issue persists.