将WCF服务部署到IIS 6

时间:2013-12-30 10:41:54

标签: visual-studio-2010 wcf iis deployment web-config

我使用VS2010创建了一个wcf服务,当我从VS2010运行它时,它正常工作,但是当我在IIS 6上部署它时(根据this帖子),它不起作用。

我做了这个步骤:

  1. 我在我的服务器(C:\WCFServices\HRService)中创建了一个文件夹,并将HRService.svc和web.config复制到该文件夹​​,并授予ASPNET用户对此文件夹的完全访问权限。
  2. 我在上面的文件夹中创建了一个Bin文件夹,并将我的服务dll复制到其中。
  3. 我在我的默认网站(HR)中创建了新的虚拟目录:
  4. enter image description here

    我的.svc个文件,web.Configs如下:

    我的.svc文件

    <%@ ServiceHost Language="C#" Debug="true" Service="HumanResourceService.HRService" %>
    

    我的web.Config

    <?xml version="1.0"?>
    <configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="NewBinding0" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="HumanResourceService.HRService">
      <endpoint address="" binding="basicHttpBinding"
         bindingConfiguration="" contract="HumanResourceService.IHRService" >
         <identity>
           <dns value="localhost"/>
         </identity>
      </endpoint>
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
     </service>
     </services>
     <behaviors>
     <serviceBehaviors>
       <behavior>
         <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="false"/>
       </behavior>
       </serviceBehaviors>
      </behaviors>
     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    </configuration>
    

    但是当我想通过IE访问我的WCF服务时,我收到此错误: enter image description here

    有谁能告诉我,问题是什么?

2 个答案:

答案 0 :(得分:1)

确保配置文件中的服务名称与.svc文件匹配。在您发布的代码中,它没有。您的.svc文件具有“HumanResourceService.HRService”,因此<service>元素的name属性应匹配:

<service name="HumanResourceService.HRService">

此外,这是一个RESTful服务还是SOAP?我问,因为您使用webHttpBinding作为服务,这是针对REST的。如果不是,我建议basicHttpBindingwsHttpBinding

如果是REST,则将其添加到配置文件的行为部分:

<endpointBehaviors>
  <behavior name="webBehavior">
    <webHttp />
  </behavior>
</endpointBehaviors>

答案 1 :(得分:0)

我发现了问题。 在IIS和 Web服务扩展部分中,ASP.NET V4.0.30319状态为禁止,我将其更改为允许,问题已解决。

enter image description here