2012-06-05 177 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過程)

這被阻塞的服務。

通過關閉/停止遠程服務器上任務管理器中的某些進程恢復了該服務。