Joe
Joe

Reputation: 7004

Cannot create an instance of the abstract class or interface on WCF Silverlight Service

I'm working through two tutorials to create a super simple WCF web service and Silverlight app.

Buiding a Service

Accessing a Service from Silverlight

Everything was going fine. I created my service:

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace TestOnline.Web.Data
{
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DataService
    {
        [OperationContract]
        public String TestService()
        {
            return "Service Worked!";
        }
    }
}

I added it as a service reference, then tried to create an instance but I'm getting the error "Cannot create an instance of the abstract class or interface" on the line "proxy = new DataService();"

I pretty much followed the steps of the tutorial exactly, I'm unsure what I've missed. I've certainly not seen many Service examples with constructors, and the reference code is auto-generated - so I don't want to go adding them manually to that.

Does anyone know of a solution/what I've done wrong? Thanks

using System.ServiceModel;
using TestOnline.ServiceReference1;

namespace TestOnline
{
    public partial class MainPage : UserControl
    {
        DataService proxy;

        public MainPage()
        {
            InitializeComponent();
            proxy = new DataService();
        }

        private void TestServiceButton_Click(object sender, RoutedEventArgs e)
        {
            //call service and get response
        }
    }
}

Upvotes: 0

Views: 1992

Answers (1)

toadflakz
toadflakz

Reputation: 7934

You should be creating an instance of the generated proxy client class.

It'll be named DataServiceClient() if it's been added correctly.

Upvotes: 1

Related Questions