我有一个简单的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引用服务 . 我在其他地方读过,如果它在一个服务 Contract 中被积极使用,你只能看到数据 Contract ,但确实如此 .
1 回答
好 . 我已经解决了这个问题:
右键单击DLL中的服务引用
点击'配置服务参考...'
未选中"Resuse types in referenced assemblies" .
tbh我不知道为什么会这样,但确实...... [盖尔耸耸肩]