在IIS5.1(XP)中承载WCF服务的步骤

Kri*_*mar 1 wcf iis-5

我开发了一个示例WCF服务.我想知道在IIS 5.1(XP)中托管它的步骤

mar*_*c_s 5

1)您需要一个IIS虚拟目录 - >使用IIS管理器创建它

2)您需要一个引用您的服务的*.svc文件 - 它是一个文本文件,它必须位于刚刚创建的虚拟目录中,它将类似于:

<% @ServiceHost Service="YourNameSpace.YourServiceClass" 
                Language="C#" Debug="False" %>
Run Code Online (Sandbox Code Playgroud)

如果您的WCF服务类位于部署到虚拟目录下面的"bin"目录的程序集中,则该方法有效.

如果您碰巧在"App_Code"目录(我推荐)的"代码隐藏"文件中包含您的实际服务代码,那么您需要在*.svc文件中使用此内容:

<% @ServiceHost Service="YourServiceClass" 
                CodeBehind="~/App_Code/YourServiceClass.cs"
                Language="C#" Debug="False" %>
Run Code Online (Sandbox Code Playgroud)

3)您需要在web.config中使用您的配置 - 根据您的需要,您至少需要<service>标签加上可能更多:

<system.serviceModel>
   <services>
      <service name="YourNameSpace.YourServiceClass"
               behaviorConfiguration="MetadaTaEnabled">
         <endpoint address="" 
                   binding="wsHttpBinding" 
                   contract="YourNameSpace.IYourService" />
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MetadaTaEnabled">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
Run Code Online (Sandbox Code Playgroud)

在这里,您需要决定使用哪种绑定(协议).

如果您完成所有这些,并且一切都成功,您应该能够使用IE(http://yourserver/virtualdirectory/YourService.svc)浏览到您的虚拟目录URL,并查看您的服务的"登录页面".