创建单个文件WCF以测试IIS设置

时间:2009-01-16 14:56:20

标签: wcf iis-6

是否可以创建单个.svc文件(WCF服务),我可以上传到我的服务器并测试它是否正确处理WCF文件?即它被配置为托管WCF服务。

(我有一个IIS6盒子,我必须测试)

1 个答案:

答案 0 :(得分:4)

您可以在svc文件中使用内联编码:

%@ ServiceHost Language="C#" Debug="true" Service="MyService.MyService" %>
using System;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace MyService
{
    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        int MyMethod(int x, int y);
    }

    public class MyService : IMyService
    {
        public int MyMethod(int x, int y)
        {
            return ((x + y) * 2);
        }
    }
}

但您还需要在Web服务器上配置web.config文件和虚拟目录:

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

  <system.web>
    <compilation debug="false" />
  </system.web>

  <system.serviceModel>
    <services>
      <service name="MyService.MyService">
        <endpoint address="" binding="wsHttpBinding" contract="MyService.IMyService" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

但基本上如果您的Web服务器安装了IIS 6.0和.NET 3.0,那么在它上运行WCF服务时应该没有问题。