2016-02-11 50 views
1

我創建了一個基本的WCF服務。它在下面顯示的行處引發異常。參數異常未處理(實體框架,WCF)

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

類型「System.ArgumentException」未處理的異常發生在System.ServiceModel.dll 其他信息:ServiceHost的只支持類服務類型。

+0

是什麼'ITransactionService1'樣子? – mike

+1

我認爲你需要傳遞類似'typeof(MyApplication.ConcreteTransactionService)'看起來你正在獲取接口的類型而不是實現。 –

+0

@mike只是這就是它的接口..公共接口ITransactionService1 { [OperationContract的] [FaultContract(typeof運算(MyException))] [TransactionFlow(TransactionFlowOption.Allowed) 無效InsertData(INT ID,字符串名稱); } public class MyException { [DataMember] public string ErrorText {get;組; } } –

回答

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)); 
+0

It Worked ..謝謝:) –