“ServiceChatClient”不包含“SendImage”的定义,并且找不到接受类型的第一个参数的扩展方法

问题描述 投票:0回答:0

我正在编写一个程序:“在 C# 中创建客户端-服务器程序。WCF 上的网络聊天”并发生以下错误 'ServiceChatClient' 不包含 'SendImage' 的定义并且没有可访问的扩展方法 'SendImage' 接受第一个可以找到“ServiceChatClient”类型的参数(您是否缺少 using 指令或程序集引用?)

我要调用的方法:

namespace ChatClient
{
    public partial class MainWindow : Window, IServiceChatCallback
    {
        bool isConnected = false;
        ServiceChatClient client;
        int ID;

        public MainWindow()
        {
            InitializeComponent();
        }
        private void btnSelectImage_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Image files (*.jpg, *.jpeg, *.png) | *.jpg; *.jpeg; *.png";

            if (openFileDialog.ShowDialog() == true)
            {
                string imagePath = openFileDialog.FileName;
                string imageName = Path.GetFileName(imagePath);

                byte[] imageData;
                using (FileStream fs = new FileStream(imagePath, FileMode.Open))
                {
                    imageData = new byte[fs.Length];
                    fs.Read(imageData, 0, imageData.Length);
                }

                if (client != null)
                {
                    client.SendImage(imageData, imageName, ID);
                }
            }

        }
    }
}

我调用的方法:

namespace wcf_chat
{
    [ServiceContract(CallbackContract = typeof(IServerChatCallback))]
    public interface IServiceChat
    {
        [OperationContract(IsOneWay = true)]
        void SendImage(byte[] imageData, string imageName, int id);
    }
}

这里是 SendImage 的实现:

public void SendImage(byte[] imageData, string imageName, int id)
        {
            var user = users.FirstOrDefault(i => i.ID == id);
            if (user != null)
            {
                string answer = DateTime.Now.ToShortTimeString() + ": " + user.Name + " sent an image: " + imageName;
                foreach (var item in users)
                {
            item.operationContext.GetCallbackChannel<IServerChatCallback>().MsgCallback(answer);
                }
                string path = Path.Combine(Environment.CurrentDirectory, "Images", imageName);
                File.WriteAllBytes(path, imageData);
            }
        }

不知道在这里能做什么 谢谢你的帮助

c# wpf wcf
© www.soinside.com 2019 - 2024. All rights reserved.