简体   繁体   English

Azure WCF服务无法连接到SQL Azure

[英]Azure WCF service can't connect to SQL Azure

I'm new to Azure and I'm doing a small test: 我是Azure的新手,正在做一个小测试:

I have a SQL Azure database and I use EF6. 我有一个SQL Azure数据库,并且使用EF6。

I also have a cloud service which connects to the Azure database (a "Windows Azure Cloud Service" with 1 web role). 我也有一个连接到Azure数据库的云服务(具有1个Web角色的“ Windows Azure云服务”)。

My service has 2 methods: 我的服务有2种方法:

  1. GetString() : returns a string. GetString() :返回一个字符串。
  2. GetUsers() : return users from table [User] in my Azure database (returns IEnumerable<User> ) GetUsers() :从我的Azure数据库中的表[User]返回用户(返回IEnumerable<User>

When I call GetString() it works fine. 当我调用GetString()它可以正常工作。

when I call GetUsers() I get the following error: 当我调用GetUsers() ,出现以下错误:

The underlying connection was closed: The connection was closed unexpectedly. 基础连接已关闭:连接意外关闭。

I've also tried using the WCF Test Client and get the same error. 我也尝试过使用WCF测试客户端,并得到相同的错误。

When I create a console app which connects to my SQL Azure (with the same connection string), everything works fine and I get a list of my users from the database. 当我创建一个连接到我的SQL Azure的控制台应用程序(使用相同的连接字符串)时,一切正常,并且从数据库中获得了我的用户列表。

The problem only happens when connecting to the database from within the Azure service. 仅当从Azure服务内部连接到数据库时,才会发生此问题。

My SQL Azure is configured to allow WINDOWS AZURE SERVICES. 我的SQL Azure配置为允许WINDOWS AZURE SERVICES。

Any ideas? 有任何想法吗?

Thanks! 谢谢!

** UPDATE **

When I use the service locally I get the following error while calling GetUsers: 当我在本地使用服务时,在调用GetUsers时出现以下错误:

An error occurred while receiving the HTTP response to localhost:50119/MyService.svc. 收到对localhost:50119 / MyService.svc的HTTP响应时发生错误。 This could be due to the service endpoint binding not using the HTTP protocol. 这可能是由于服务端点绑定未使用HTTP协议。 This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). 这也可能是由于服务器终止了HTTP请求上下文(可能是由于服务关闭了)。 See server logs for more details. 有关更多详细信息,请参见服务器日志。

I figured this out: 我想通了:

Behaviors, Bindings and Services was not configured in my web.config file. 行为,绑定和服务未在我的web.config文件中配置。 I thoughts it should be configured by default and probably i was mistaken. 我认为应该默认配置它,可能我弄错了。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM