参数异常未处理(实体框架,WCF)

时间:2016-02-11 17:34:17

标签: c# wcf entity-framework-4 argumentexception

我创建了一个基本的WCF服务。它在下面的行中引发异常。

  ServiceHost host = new ServiceHost(typeof(MyApplication.ITransactionService1));

未处理的类型' System.ArgumentException'发生在System.ServiceModel.dll中 附加信息:ServiceHost仅支持类服务类型。

1 个答案:

答案 0 :(得分:1)

ServiceHost Constructor (Type, Uri[])期望具体类型,而不是接口。

假设ITransactionService1是您的服务合同,并且您已在TransactionService1中实施了该合同:

namespace MyApplication
{

    [ServiceContract]
    public interface ITransactionService1
    {

        [OperationContract]
        int DoSomething(string arg);
    }

    public class TransactionService1 : ITransactionService1
    {

        // Implementation logic
    }
}

你要传递MyApplication.TransactionService1

ServiceHost host = new ServieHost(typeof(MyApplication.TransactionService1));