从服务函数返回具有List数据成员的对象 [英] Returning an object with a List data member from a service function

查看:63
本文介绍了从服务函数返回具有List数据成员的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我编写了一个WCF服务,该服务在其中声明一个类,该类的数据成员之一是List<sting>.

在Silverlight应用程序中,我调用一个服务函数,该函数返回该类的对象.

出于某种原因,我获得了具有所有数据成员的对象,但List<string>为空.

有谁可以帮忙吗?

我的服务如下:

Hi,

I wrote a WCF service that declairs a class in it, One of the data members of the class is a List<sting>.

In a Silverlight application, I call a service function that returns an object of that class.

For some reason, I get the object with all the data members but the List<string> is null.

Could any one help?

My service looks like this:

    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        Equation Resolve(Equation equation);
    }
    
    public class Service1 : IService1
    {
        public Equation Resolve(Equation equation)
        {
            Equation e = new Equation();
            e.ResultsList =getData();
            return e;
        }
}


该类如下所示:


The class looks like this:

[DataContract]
public class Equation
{
     public double C { get; set; }
     [DataMember]
      public NumOfResults numOfResults { get; set; }
     [DataMember]
    public ResultType resultType { get; set; }
     [DataMember]
     public List<string> ResultsList{ get; set; }

 }


在Silverlight中,我有一个功能:


In the silverlight i have a function:

private void btnGetResult2_Click(object sender, RoutedEventArgs e)
       {
           svc.ResolveCompleted += new  EventHandler<ServiceReference.ResolveCompletedEventArgs>(svc_ResolveCompleted);
           svc.ResolveAsync(equation1);
       }
      void svc_ResolveCompleted(object sender, ServiceReference.ResolveCompletedEventArgs e)
       {
         Equation equ=e.Result;
         List<string> res=equ.ResultList;// for some reason allways null!!
       }

推荐答案

ResultList是否太大?您可能需要使用maxbuffersize 属性 [ ^ ].
我看不到此代码有任何其他问题.尝试检查服务中getData()中是否有返回值.
Is there ResultList too large? You might want to play around with the maxbuffersize attribute[^].
I don''t see any other problem with this code. Try to check if there is a return value in getData() in your service.


这篇关于从服务函数返回具有List数据成员的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆