简体   繁体   中英

The Type or Namespace “MyServiceClient” Could not be Found

I've just completed this wcf duplex tutorial , but upon going over my code I encountered this error:

Severity    Code    Description   Line
Error   CS0246  The type or namespace name 'MyServiceClient' could not be found (are you missing a using directive or an assembly reference?) ClientSide 15

My usings all seem to be in order, and I've googled this error numerous times with no luck.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;

namespace ClientSide
{
    class Program
    {
        static void Main(string[] args)
        {
            InstanceContext callback = new InstanceContext(new ClientCallback());
            MyServiceClient client = new MyServiceClient(callback);
            client.Open();
            client.Register();
            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
            client.Close();
        }
    }
}

Is MyServiceClient a type or a namespace?

Any help would be much appreciated, I'm using Visual Studio 2015.

In this case MyServiceClient should be the name of the client class generated when you did "Add Service Reference".

To verify the name of the generated class, in windows explorer navigate to the directory containing your service references (typically eg <ProjectName>\\Service References\\<ServiceReferenceName> , and open the file Reference.cs

Inside of Reference.cs, look for a class that inherits from System.ServiceModel.ClientBase . The derived class is the your service client class that you should use to interact with the web service.

So, for example, if Reference.cs contained

public partial class BlahServiceSoapClient : System.ServiceModel.ClientBase<global::MyProject.MyService.BlahServiceSoap>, global::MyProject.MyService.BlahServiceSoap

Note, that depending on the reference, it could be a different subclass of System.ServiceModel.ClientBase that you see in the Reference.cs file. Since this question is specifically about the duplex client, you would see System.ServiceModel.DuplexClientBase

Then your service class would be BlahServiceSoapClient , so you would do

BlahServiceSoapClient client = new BlahServiceSoapClient(callback);

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