简体   繁体   English

WCF服务问题

[英]WCF Service Problems

I'm having trouble setting up my WCF Service to an IIS server. 我在将WCF服务设置到IIS服务器时遇到问题。 The current setup I have is a WCF service written in C# that accesses an external database (located on a different server, different location than our IIS server) and an ASP.NET web site that consumes the service on our server, and uses it's methods to query, then display some data. 我当前使用的设置是用C#编写的WCF服务,该服务可访问外部数据库(位于与IIS服务器不同的服务器,且位置不同于我们的IIS服务器),以及一个使用服务器上的服务并使用其方法的ASP.NET网站。查询,然后显示一些数据。

Before I uploaded the Service and website to our server, I tested it using the default setup done by Visual Studio. 在将服务和网站上传到我们的服务器之前,我已经使用Visual Studio完成的默认设置对其进行了测试。 This test led to promising results, because when I let visual studio host the service (and whatever else it does in order to setup the environment for testing) and consume it with the website, everything went smoothly, and all of my queries went through flawlessly. 这项测试带来了可喜的结果,因为当我让Visual Studio托管服务(以及为设置测试环境而进行的其他任何操作)并在网站上使用它时,一切都进行得很顺利,并且我所有的查询都顺利进行了。

I can upload the service fine, consume it fine with the website, but I have problems when my service makes queries to the external database. 我可以很好地上传服务,可以在网站上正常使用它,但是当我的服务向外部数据库查询时,我遇到了问题。 I get an "underlying provider failed on open" error when an actual query is made. 进行实际查询时,出现“底层提供程序在打开时失败”错误。 I've tried a few different things and I couldn't find an answer. 我尝试了几种不同的方法,但找不到答案。 For legal reasons , I'm not allowed to upload the code, but I think this problem is due to incorrect setup on the server. 出于法律原因,我不允许上载代码,但是我认为此问题是由于服务器上的设置不正确造成的。

Assuming that you're using Entity Framework, that problem almost always indicates that there is an issue establishing a connection to your database. 假设您使用的是Entity Framework,那么该问题几乎总是表明存在与数据库建立连接的问题。 Check your connection string and make sure that the server and instance names are correct, and that the user your service is running under has access to the database. 检查您的连接字符串,并确保服务器和实例名称正确,并且服务在其下运行的用户有权访问数据库。 If you're hosting in IIS, this would usually be a service account (eg NETWORK SERVICE) or local system account. 如果您在IIS中托管,则通常是服务帐户(例如NETWORK SERVICE)或本地系统帐户。

The issue ended up being the connection string in the end. 问题最终是最后的连接字符串。 On my local machine, the name of the server was resolved with the Hosts file, but the server had nowhere to resolve the name of the server mentioned in the connection string. 在我的本地计算机上,服务器的名称是使用Hosts文件解析的,但是服务器无处解析连接字符串中提到的服务器的名称。 This was causing the issue. 这是造成问题的原因。 This has been resolved by updating the server hosts file. 通过更新服务器主机文件已解决此问题。

I've gotten this error on new installations of SQL Server, and I fixed it by enabling Named Pipes in SQL Server Configuration Manager. 我在新安装的SQL Server上遇到此错误,并通过在SQL Server配置管理器中启用命名管道来修复此错误。 Could be the same issue you're having. 可能是您遇到的相同问题。

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

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