我想从 Windows Azure
中的 Mobile Service
访问 WCF 服务
。为此,我使用 Service Bus Relay
连接,该连接配置了凭据来调用 WCF 服务
。
当我在本地计算机上发布此移动服务
时,我可以毫无问题地调用WCF服务
。
但是当我在 Azure 上发布此移动服务
时,在尝试访问它时出现以下错误。 IService1 是 WCF 服务的契约(Contract)。我使用此契约(Contract)在移动服务的 Web.Config 文件中定义了端点。
你能帮我解决这个问题吗?
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.
编辑: 经过进一步调查这个问题,我发现,当我们将其托管在云中时,通过添加服务引用生成的代理类并没有获取 Web.config 中定义的端点定义。但是,当该服务在我的计算机的 azure 模拟器上运行时,它会从 Web.config 获取端点定义。
因此,为了解决该问题,我必须以编程方式定义端点并使用 ChannelFactory 类来调用 WCF 服务。
对于为什么移动服务无法读取云中的 Web.config 有什么想法吗?
最佳答案
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
所以我猜移动服务中的 .config 文件有一些特别之处,但我不知道更多。以编程方式初始化 WCF 是一个很好的解决方案。
关于azure - 无法从 Azure 中的移动服务访问 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27164017/