Unable to access WCF service from Mobile Service in Azure

268 views Asked by At


I wanted to access WCF service from Mobile Service in Windows Azure. For this, I am using Service Bus Relay connection which is configured with credentials to call the WCF service.

When I published this Mobile Service on my local machine, I could call WCF service without any issue.

But when I published this Mobile Service on Azure, it is giving following error when trying to access it. IService1 is contract for WCF Service. I defined endpoint in Web.Config file in Mobile Service with this contract.

Can you help me resolve this?

Exception=System.InvalidOperationException: Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

EDIT: Upon further investigating this issue, I found out that, proxy class, which is generated by adding service reference, is not picking up the endpoint definition defined in Web.config when we host it in the cloud. But when the service is run on my machine's azure emulator, it is picking up endpoint definition from Web.config.

So, to resolve the issue, I had to define endpoint programmatically and use the ChannelFactory class to call the WCF service.

Any thoughts on why Mobile Service is unable to read Web.config in cloud?

1

There are 1 answers

0
Guillaume On

You can set the app settings as key/value pairs in the appSettings section of the .NET backend project’s Web.config file. These values are used when testing a .NET backend project on the local computer. When running in Azure, these values are ignored and the portal settings are used instead.

http://msdn.microsoft.com/en-us/library/azure/dn529070.aspx

So I guess there is something special about .config file in Mobile Services but I don't know more. Initializing your WCF programmaticaly is a good solution.