2012-06-05 173 views
18

我正在通过WCF工作,它在本地主机上正常工作。在将它放到生产服务器后,它给我一个例外:“请求的服务'http://global-kazway.kz/Service1.svc'无法激活。请参阅服务器的诊断跟踪日志以获取更多信息。”无法激活WCF服务

我是服务新手,一直试图解决这个问题近3个小时。

这里是客户端的App.config;

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections></configSections> 
    <connectionStrings> 
    <add name="TestProject.Properties.Settings.DBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Documents\visual studio 2010\Projects\TestProject\TestProject\AppData\DB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /><add name="DBEntities" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=C:\Users\1\Documents\visual studio 2010\Projects\TestProject\TestProject\AppData\DB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /><add name="DBEntities1" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\AppData\DB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
      useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://global-kazway.kz/Service1.svc" binding="basicHttpBinding" 
     bindingConfiguration="BasicHttpBinding_IService1" contract="kazwayServiceReference.IService1" 
     name="BasicHttpBinding_IService1" /> 
    </client> 
    </system.serviceModel> 
</configuration> 
+1

也提供服务的配置,请。 – TarasB

+2

Hey Nate。我看到你从来没有把你的任何问题都标记为答案!如果你想在这里的人回答你的问题,开始还钱了明显的答案。因此,例如,如果13-upvoted的信息对您有帮助,请将其标记为答案。 –

回答

61

解决WCF应用程序故障的第一步是打开浏览器并输入服务URI。所以基于客户端:你会导航到http://global-kazway.kz/Service1.svc

现在看看你会得到什么样的结果。例外?服务屏幕?通常你可以从这个屏幕上获得最好的信息!有时它会指出你的问题是什么,比如缺少一种行为。

将您的web.config与部署的web.config条目进行比较。你也可以在那里找到一些东西。最后你可能只需要管理你的文件夹的安全性。但浏览器显示屏可以很清楚地为你拼出一切。

3

我工作过WCF和它localhost.After工作得很好我把它放置到生产服务器,它thows我一个例外“所请求的服务,“http://global-kazway.kz/Service1 .SVC”不能启动。查看服务器的诊断跟踪日志的详细信息

This MSDN article describes how to configure tracing on the server。完成之后,您可以查看服务器的诊断跟踪日志,并且可能会发现问题。

2

对有错误的更详细说明,请在服务的你的web.config文件中插入下面的代码: -

<serviceBehaviors> 
    <behavior name="MyServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 

然后使用这个服务行为您服务是这样的: -

<service name="MyService" behaviorConfiguration="MyServiceBehavior" > 
     <endpoint address="" binding="basicHttpBinding" xxxx="" xxxxx="" xxxxx="" xxxx="" xxxx="" /> 
     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://ServerAddress:AnyPortIfspecified/VirtualDirname"/> 
      </baseAddresses> 
     </host> 
     </service> 

这会给你一个错误的详细描述。

,你可以尝试的第二件事是检查: -

<host> 
     <baseAddresses> 
      <add baseAddress="http://ServerAddress:AnyPortIf specified/VirtualDir name"/> 
     </baseAddresses> 
     </host> 

确保您的基地址不是localhost。 TC

+0

我正在寻找添加'行为'到我的应用程序来到这个问题的底部,但它看起来像你的答案是不完整的。 “此: - ”之后什么也没有。不过,我已经提出了你的答案,因为它指出我的方向是正确的。 –

5

我正在开展一个项目,并面临同样的问题。 当我查看事件查看器来追踪错误时,我发现问题出在哪里。

事件查看器消息:

Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/7540993 
Exception: System.ServiceModel.ServiceActivationException: The service '/CODWebService/Service1.svc' cannot be activated due to an exception during compilation. The exception message is: Memory gates checking failed because the free memory (164065280 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.. ---> System.InsufficientMemoryException: Memory gates checking failed because the free memory (164065280 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element. 

然后我说下面的代码,我服务的web.config文件。

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="1" /> 

这个元素应该放在<system.serviceModel>

1

我可以按以下使用Visual Studio 2013的步骤来解决问题:

  1. 转到您的项目,你必须文件夹你* .svc文件
  2. 右击* .svc文件 - >浏览器查看
  3. 验证,如果你能够浏览服务

enter image description here

  1. 转至你有你的app.config文件或要使用该服务项目文件夹。
  2. 右键项目 - >添加 - >服务参考
  3. 点击发现 - >在服务选择服务 - >提供所需的名称为您服务的参考 - >点击OK
  4. 这将创建 “ServiceReference1” 的文件夹下的 “服务引用” &自动创建/更新app.config文件

enter image description here

1

第一件事,以服务URL地址(例如。 http://youservice:808/Area.Service/Service.svc),并把它放到浏览器URL字段,检查该服务是否正在运行。

在我的情况下,它没有运行。

远程服务器有一个过程运行中使用的很多或CPU和RAM(SQL过程)

这被阻塞的服务。

通过关闭/停止远程服务器上任务管理器中的某些进程恢复了该服务。