我有一些问题。我在WCF技术上进行了简单的聊天。聊天程序由服务器部分和客户端部分组成。我需要从数据库中打包一个表并将其发送给客户端。但我不知道如何正确地做到这一点,所以我决定这样做,当然,我有一个问题:客户没有收到表。它可能是什么?
////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace ChattingInterfaces ///chatting interface
{
[ServiceContract(CallbackContract=typeof(IClient))]
public interface IChattingService
{
[OperationContract]
List<ITableContent> content();
}
}
////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using ChattingInterfaces;
using System.Collections.Concurrent;
namespace ChattingServer /// server part of program
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class ChattingService : IChattingService
{
public List<ITableContent> content()
{
List<ITableContent> result = new List<ITableContent>();
result.Add(new TableContent()); /// packing table to client
return result;
}
}
}
////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace ChattingInterfaces
{
public interface ITableContent
{
List<string> nick { get; set; }
List<bool> status { get; set; }
List<decimal> id { get; set; }
}
}
////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using ChattingInterfaces;
using DataContext1;
using Devart.Data.Oracle;
using System.Data;
namespace ChattingServer
{
public class TableContent:ITableContent
{
ABDDataContext db;
List<object> rList;
List<string> ITableContent.nick
{
get
{
return db.TABLEs.AsParallel().Select(f => f.NICK).ToList();
}
set
{
}
}
List<bool> ITableContent.status
{
get
{
return db.TABLEs.AsParallel().Select(f => f.STATUS).ToList();
}
set
{
}
}
List<decimal> ITableContent.id
{
get
{
return db.TABLEs.AsParallel().Select(f => f.ID).ToList();
}
set
{
}
}
}
}
////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ChattingInterfaces;
using System.ServiceModel;
namespace ChattingClient
{
public partial class MainWindow : Window
{
public static IChattingService Server;
private static DuplexChannelFactory<IChattingService> _channelFactory;
public MainWindow()
{
InitializeComponent();
_channelFactory = new DuplexChannelFactory<IChattingService>(new ClientCallBack(this),"ChattingServiceEndPoint");
Server = _channelFactory.CreateChannel();
var p = Server.content(); /// CommunicationException was unhandled!
}
////////////////////////////////////////
答案 0 :(得分:0)
你有知识类型的问题,在WCF中发送接口是非常有问题的 - 因为你需要创建知识型解析器。而对于使用WCF聊天的应用程序就像用1吨炸弹打钉子一样。为什么不使用自动托管的WebAPI服务器,并使用信号器客户端?
无论如何你的tablecontent没有datacontract属性 - WCF不知道串行什么