【发布时间】:2012-11-09 13:32:59
【问题描述】:
我有一个简单的 WCF 日志记录服务..
namespace WCFServiceLibrary
{
[ServiceContract]
public interface ILog
{
[OperationContract]
string InsertLogItem(LogItem logItem);
}
[DataContract]
public class LogItem
{
private string _Text = string.Empty;
[DataMember]
public string Text
{
get { return _Text; }
set { _Text = value; }
}
}
}
我有一个客户端和一个 DLL,都在同一个解决方案中。
如果我从客户端引用服务,我可以看到 DataContract。 如果我从 DLL 引用服务,我看不到 DataContract。
我的意思是我将服务引用为 LogService,并在客户端中有此代码...
static LogService.LogClient logService = new LogService.LogClient();
//create log item - <<< Compile error in DLL on following line >>>
var itemTolog = new LogService.LogItem { Text = "log this"};
string result = logService.InsertLogItem(itemTolog);
那么它可以正常工作,但是如果DLL中相同的代码,则由于LogService.LogItem不可见而无法编译,并报告以下错误
The type or namespace name 'LogItem' does not exist in the namespace 'MyDll.LogService' (are you missing an assembly reference?)
当从 dll 引用服务时,dataContract "LogItem" 根本不在对象资源管理器中,但如果从客户端 exe 引用,则它存在。
什么给了?不用说我想从 DLL 中引用服务。 我在其他地方读到,只有在其中一个服务合同中积极使用数据合同时,您才能看到它,但确实如此。
【问题讨论】:
-
“看不到数据合同”是什么意思?您是否在运行时遇到问题,或者在编写代码时无法声明 wcf 服务的实例?
-
@Steve 希望现在通过包含在 DLL 中引用服务时失败/不可见的代码让自己更清楚。
标签: c# .net visual-studio-2010 wcf