首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

WCF入门初学者有关问题

2012-11-15 
WCF入门菜鸟问题我最近在学WCF,碰到一个问题,提示“ServiceHost 仅支持类服务类型。”错误,请问如何解决?usin

WCF入门菜鸟问题
我最近在学WCF,碰到一个问题,提示“ServiceHost 仅支持类服务类型。”错误,请问如何解决?

using System.ServiceModel;
namespace TestServer
{
  [ServiceContract]
  public interface ITestSevice
  {
  [OperationContract]
  int Getsum(int num1, int num2);  
  }  
}

namespace TestServer
{
  public class TestService : ITestSevice
  {
  public int Getsum(int num1, int num2)
  {
  return num1+num2;
  }
  }
}

宿主app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
  <behaviors>
  <serviceBehaviors>
  <behavior name="sumServiceBehavior">
  <serviceMetadata httpGetEnabled="true"/>
  </behavior>
  </serviceBehaviors>
  </behaviors>
  <services>
  <service name="TestServer.TestService" behaviorConfiguration="sumServiceBehavior">
  <host>
  <baseAddresses>
  <add baseAddress="http://localhost:8089/MySumService"/>
  </baseAddresses>
  </host>
  <endpoint address="" binding="wsHttpBinding" contract="TestServer.ITestService" />
  </service>
  </services>
  </system.serviceModel>
</configuration>

宿主执行服务:
private void button1_Click(object sender, EventArgs e)
  {  
  try
  {
  ServiceHost host = new ServiceHost(typeof(TestServer.ITestSevice));//=>这句报错:ServiceHost 仅支持类服务类型。”
  host.Open();
  richTextBox1.AppendText("WCF服务已经成功启动");
  }
  catch (Exception ex)
  {
  richTextBox1.AppendText("WCF服务启动中错误:" + ex.Message);

  }
  }

执行到ServiceHost host=new ....这句报错“ServiceHost 仅支持类服务类型。”请问如何解决?

[解决办法]
ServiceHost host = new ServiceHost(typeof(TestServer.TestServer));

热点排行