【发布时间】:2013-11-25 14:03:12
【问题描述】:
我正在为医疗数据实施分布式处理系统。我有多个客户端和服务器。客户端有数据,他们向服务器发送请求进行处理。
我必须将两个值传输到服务器并返回一个列表。服务器实现定义为:
[ServiceContract]
public interface ServerInterface
{
[OperationContract]
List<Triangle> ServerFunction(Grid g, double isolevel);
}
public class ServerImpl : ServerInterface
{
public List<Triangle> ServerFunction(Grid g, double isolevel)
{/*Implementation*/}
}
网格类定义为:
[Serializable]
public class Grid
{
public Point3D[] p = new Point3D[8];
public Int32[] val = new Int32[8];
}
Triangle 类为
[Serializable]
public class Triangle
{
public Point3D[] p = new Point3D[3];
}
我创建了客户端和服务器端实现,isolevel 值可以正常传递,但网格没有正确传递。
服务器使用此代码创建 WCF 服务:
Uri baseAddress = new Uri("http://localhost:6525/ServerObject");
using (ServiceHost host = new ServiceHost(typeof(ServerImpl), baseAddress))
{
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
Console.ReadKey();
}
调用服务器获取结果的代码部分是:
var myBinding = new BasicHttpBinding();
var myEndPoint = new EndpointAddress("http://localhost:6525/ServerObject");
var myChannelFactory=new ChannelFactory<ServerInterface>(myBinding,myEndPoint);
ServerInterface si=null;
si = myChannelFactory.CreateChannel();
List<Triangle> triList=si.ServerFunction(Grid g,double isoValue);
它从不返回三角形列表(总是返回 null)。
此代码在转换为分布式之前经过测试并且工作正常。
我正在使用 WCF,我尝试将 Grid 和三角形转换为字符串值并传递它们,它可以工作,但速度很慢。该算法本身需要大量时间,因此不需要额外的处理时间。有什么想法吗?
【问题讨论】:
-
你试过用 DataContract 代替 Serializable 吗?
-
我试过了,但到达服务器的 Grid 对象为空。
-
愚蠢的问题,但是当您调用服务时,您是否确认您的网格对象不是
null? -
是的。它在通过之前创建并检查。当我尝试从服务器访问 gridcell 对象时,它说对象引用未设置为对象的实例。
标签: c# wcf serialization distributed-computing