简体   繁体   中英

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
        }
    }
}

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM