【发布时间】:2012-02-07 00:59:26
【问题描述】:
我查看了一些关于此主题的类似帖子,但并没有完全找到我要查找的内容,因此我将解释我在做什么以及我遇到的问题。
我有一个 MVC3 应用程序和一个保存我的模型数据的类库。例如,我的域模型项目在这里有一个名为 CLUser 的类:
public class CLUser
{
public int ID { get; set; }
[Display(Name = "User Name")]
[StringLength(50, ErrorMessage = Util.ERRORMESSAGE_STRING_LENGTH_50)]
public string UserName { get; set; }
public string Password { get; set; }
public DateTime PasswordExpiration { get; set; }
public bool LockedOut { get; set; }
public string LockedOutReason { get; set; }
[Display(Name = "Security Question")]
public string SecurityQuestion { get; set; }
[Display(Name = "Security Answer")]
public string SecurityAnswer { get; set; }
[Display(Name = "Current Status:")]
public int Standing { get; set; }
public int MerchantID { get; set; }
public int PartnerID { get; set; }
public DateTime CreatedDtTm { get; set; }
public DateTime UpdatedDtTm { get; set; }
public List<CLPermission> UserPerms { get; set; }
}
然后我有一个 WCF 服务,它引用具有模型 CLUser 的同一项目。所以在我的 WCF 中,我有一个名为
的操作合同[OperationContract]
GetUser(string userName, string password);
因此暴露在 MVC 项目中。
所以这就是问题所在。我想将 CLUser 对象设置为等于我对 GetUser 的 WCF 服务调用。看起来像这样:
ServiceClient MyService = new ServiceClient();
CLUser Usr = MyService.GetUser(userName, password);
但是,当我这样做时,我会收到如下错误:
无法将类型 Auth.CLUser 隐式转换为 Auth.CLUser[C:\ ....\Auth.DLL]
如果 WCF 和 MVC 应用程序都引用同一个 DLL,他们就不能使用同一个对象吗?
【问题讨论】:
-
尝试重建DLL,构建服务,启动服务,更新服务引用,构建客户端。
-
好的,我今天就来看看它是否有效。
-
好吧,我觉得很傻。我收到该错误的原因是,当我添加服务时,我为该服务提供了与我的 WCF 项目相同的程序集名称。所以这就是它感到困惑的原因。只需以不同的程序集名称重新添加服务即可解决问题。
标签: c# asp.net-mvc asp.net-mvc-3 wcf