客户端中的WCF服务复杂类型访问 - 当前上下文中不存在名称obj

时间:2013-11-22 08:53:24

标签: asp.net-mvc wcf

我有wcf服务并有服务

 public Subscriber GetSubscriberDetails(int contactNo)
        {
            try
            {
                return obj.GetSubscriberDetails(contactNo);
            }
            catch (GasCylinderException ex)
            {
                throw new FaultException<GasCylinderFault>(new GasCylinderFault { Message = ex.Message, ErrorDetails = ex.ToString() });
            }
            catch (Exception ex)
            {
                throw new FaultException("unexcepted error has occured:"+ex.ToString());
            }
        }

我有对mvc项目的服务引用但是当我访问该服务时,返回的objext服务被分配给复杂类型,当我放入调试器并检查obj它 “当前上下文中不存在名称obj”

我已经在单独的程序集中定义了具有适当属性的复杂类型,如下所示

  [DataContract]
    public class Subscriber
    {
        [DataMember]
        public int ContactNo { get; set; }
        [DataMember]
        public string Name { get; set; }
        public String Address { get; set; }
        public int Year { get; set; }
        [DataMember]
        public int NoOfCylindersUsed { get; set; }
        public DateTime LastDespatchedDate { get; set; }
        [DataMember]
        public int NoOfCylindersAllocated { get; set; }
        public List<GasCylinderRequest> request { get; set; }
        public override bool Equals(object obj)
        {
            if (obj is Subscriber)
            {
                var that=obj as Subscriber;
                return (this.ContactNo == that.ContactNo) &&
                       (this.Name == that.Name) &&
                       (this.Address == that.Address) &&
                       (this.Year == that.Year) &&
                       (this.NoOfCylindersAllocated == that.NoOfCylindersAllocated) &&
                       (this.NoOfCylindersUsed == that.NoOfCylindersUsed) &&
                       (this.LastDespatchedDate == that.LastDespatchedDate) &&
                       (this.request == that.request);
            }
            return false;
        }
    }

我无法弄明白。任何帮助都会被暗示

1 个答案:

答案 0 :(得分:0)

您可以在ASP.NET项目中创建Suscriber对象吗?

如果你得到了#34; Suscriber这个名字并不存在于当前语境中#34;尝试右键单击Suscriber类型然后解析 - &gt;使用服务参考。