2012-05-19 88 views
1

我創建的Web服務庫想在這個環節http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-60-sec有什麼不對的WCF

要發佈它,我跟着鏈接http://naztek.wordpress.com/2009/08/27/host-a-wcf-library-in-iis/

,但我在運行時得到這個錯誤

Server Error in '/WCFService1' Application.

The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

web.config是:

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    <services> 
     <service name="test1.Try"> 
     <endpoint address="http://localhost:8732/Try" binding="webHttpBinding" contract="test1.Try"/> 
     </service> 
    </services> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

[InvalidOperationException: The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]

回答

1

它看起來像我從第二個鏈接(關於發佈)錯過了第3步。特別是這部分:

Change the Service attribute value from Service to the fully qualified name of the concrete class in our WCF library, e.g., RegistrationServiceLib.RegistrationService

要打開SVC文件使用右鍵 - >開放 - > XML(文本)編輯器

您應該看到這樣的事情:

<%@ ServiceHost Language="C#" Debug="true" Service="YourNamespace.Service" CodeBehind="Service.svc.cs" %> 

更改爲匹配您的服務(就像您的教程所述)。

+0

你可以解釋或更正我的代碼,我試圖設置所有限定名稱 – AMH

+0

我擴展信息在我的答案。讓我看看你的Service.svc文件的內部。 –

+0

非常感謝,但現在給出錯誤在服務'Try'實施的合同列表中找不到合同名稱'test1.Try'。任何想法如何解決你在web.config中的 – AMH