2010-12-10 132 views
0

在IIS 7.0中創建了一個新的目錄XYZ。將web.config,Service.cs和Service.svc複製到目錄。現在瀏覽http://www.mydomain.com/XYZ/Service.svc我得到'500內部服務器錯誤'。將簡單的WCF服務部署到Web服務器

這是web.cofig文件。

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/>   
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

我在想配置文件可能存在一些問題,但服務在本地機器上運行得很好。

回答

1

首先,您必須使用dll文件而不是代碼文件。編譯代碼並將dll放入「bin」文件夾中。

在第二,您沒有添加到終點web.cofnig:

<system.serviceModel> 
<!-- ... --> 
    <services> 
     <service name="SiteService"> 
      <endpoint address="" binding="basicHttpBinding" 
       contract="Name of the service interface with namespace, for exanple WebApplication1.IService1" /> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services>  
</system.serviceModel> 

並檢查SVC文件,裏面一個服務名稱應該對應一個配置文件中服務名稱。如果一項服務有一行<service name="SiteService">,則svc文件應該是

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