我有第一个项目“MyProject.Core”,我有 EDMX:
repo 类:
class MyProjectRepo : IMyProjects
{
public int NumberOfUser()
{
return new context().User.Count();
}
public string HelloWorld()
{
return "Hello World!";
}
}
界面:
public interface IMyProjects
{
int NumberOfUser();
string HelloWorld();
}
工厂:
public static class MyProjectFactory
{
private static IMyProjects _returnedObject;
public static IMyProjects GetObject()
{
lock (typeof(MyProjectFactory))
{
_returnedObject = new MyProjectRepo();
}
return _returnedObject;
}
}
测试项目“MyProject.Core.Tests”(测试通过):
[Test]
public void NumberOfUser_Test()
{
var number = MyProjectFactory.GetObject().NumberOfUser();
Assert.AreEqual(1, number);
}
[Test]
public void HelloWorld_Test()
{
var hello = MyProjectFactory.GetObject().HelloWorld();
Assert.AreEqual("Hello World!", hello);
}
我创建了一个“云”项目和一个 WCFServiceWebRole。
在 WCFServiceWebRole 中,我有这个:
public class Service1 : IService1
{
public int NumberOfUser()
{
return MyProjectFactory.GetObject().NumberOfUser();
}
public string Hello()
{
return MyProjectFactory.GetObject().HelloWorld();
}
}
[ServiceContract]
public interface IService1
{
[OperationContract]
int NumberOfUser(string login, string password);
[OperationContract]
string Hello();
}
一个测试WCF的项目,方法“Hello”返回正确的值。 这是我遇到问题的另一种方法。在 app.config 中,我有这个 :
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myproject.azurewebsites.net/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="myprojectServiceAzure.IService1" name="BasicHttpBinding_IService1" />
</client>
错误:
System.TimeoutException : The request channel timed out while waiting for a reply after 00:00:59.7138476. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. ----> System.TimeoutException : The HTTP request to 'http://MyProject.azurewebsites.net/Service1.svc' has exceeded the allotted timeout of 00:00:59.9270000. The time allotted to this operation may have been a portion of a longer timeout. ----> System.Net.WebException : The operation has timed out MyProject.Azure.Tests\Service References\MyProjectServiceAzure\Reference.cs(487, 0) : MyProject.Azure.Tests.PointageServiceAzure.Service1Client.MyMethod(String login, String password) MyProject.Azure.Tests\AzureTests.cs(18, 0) : MyProject.Azure.Tests.AzureTests.Test()
最佳答案
您检查过 Azure 防火墙规则吗?您需要“允许”WCF 服务访问 SQL Azure 数据库。根据内存,您需要选中一个复选框,该复选框允许托管应用程序访问数据库,因为默认情况下未选中此复选框。
关于c# - 在Azure上部署WCF服务,尝试访问数据库时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14068663/