1

I have created one basic WCF Service. It thrown an exception at line shown below.

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

An unhandled exception of type 'System.ArgumentException' occurred in System.ServiceModel.dll Additional information: ServiceHost only supports class service types.

3
  • What does ITransactionService1 look like? Commented Feb 11, 2016 at 17:38
  • 1
    I think you need to pass something like typeof(MyApplication.ConcreteTransactionService) It looks like you are getting the type of an interface and not the implementation. Commented Feb 11, 2016 at 17:44
  • @mike just an interface that's it.. public interface ITransactionService1 { [OperationContract] [FaultContract(typeof(MyException))] [TransactionFlow(TransactionFlowOption.Allowed)] void InsertData(int id, string name); } public class MyException { [DataMember] public string ErrorText { get; set; } } Commented Feb 11, 2016 at 17:58

1 Answer 1

1

The ServiceHost Constructor (Type, Uri[]) expects a concrete type, not an interface.

Assuming that ITransactionService1 is your service contract and that you've implemented it in TransactionService1:

namespace MyApplication
{

    [ServiceContract]
    public interface ITransactionService1
    {

        [OperationContract]
        int DoSomething(string arg);
    }

    public class TransactionService1 : ITransactionService1
    {

        // Implementation logic
    }
}

You would than pass MyApplication.TransactionService1:

ServiceHost host = new ServieHost(typeof(MyApplication.TransactionService1));
Sign up to request clarification or add additional context in comments.

2 Comments

It Worked.. Thank you :)
this raises TransactionService1 is not attributed with ServiceContractAttribute error. And requires to move ServiceContract from interface to TransactionService1 class definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.