将简单的WCF服务部署到Web服务器

时间:2010-12-10 11:52:48

标签: wcf deployment .net-4.0

在IIS 7.0中创建了一个新的目录XYZ。将web.config,Service.cs和Service.svc复制到该目录。现在正在浏览http://www.mydomain.com/XYZ/Service.svc我收到'500内部服务器错误'。

这是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 个答案:

答案 0 :(得分:1)

首先,您必须使用dll-file而不是代码文件。编译代码并将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" %>
相关问题