C# WCF DataContract仅在从客户端exe而不是DLL引用服务时可见
我有一个简单的WCF日志服务C# WCF DataContract仅在从客户端exe而不是DLL引用服务时可见,c#,.net,visual-studio-2010,wcf,C#,.net,Visual Studio 2010,Wcf,我有一个简单的WCF日志服务 namespace WCFServiceLibrary { [ServiceContract] public interface ILog { [OperationContract] string InsertLogItem(LogItem logItem); } [DataContract] public class LogItem { private str
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引用服务时,dataContract“LogiItem”不在对象资源管理器中,但如果从客户端exe引用,则在对象资源管理器中
有什么好处?不用说,我想从DLL中引用服务。
我在其他地方读到过,只有在其中一个服务契约中积极使用数据契约时,才能看到它,但它确实如此 好的。我通过以下方式解决了此问题:
- 右键单击DLL中的服务引用
- 单击“配置服务引用…”
- 未选中“恢复引用程序集中的类型”
tbh我不知道为什么这样做,但它确实。。。[盖尔语耸耸肩]好的。我通过以下方式解决了此问题:
- 右键单击DLL中的服务引用
- 单击“配置服务引用…”
- 未选中“恢复引用程序集中的类型”
tbh我不知道为什么这样做,但它确实。。。[盖尔语耸耸肩]你说的“看不见数据合同”是什么意思?您是否在运行时遇到问题,或者在编写代码时无法声明wcf服务的实例?@Steve希望通过在DLL中引用该服务时包含失败/不可见的代码来让自己更清楚。您所说的“看不到DataContract”是什么意思?您是否在运行时遇到问题,或者您在编写代码时无法声明wcf服务的实例?@Steve希望通过在DLL中引用该服务时包含失败/不可见的代码来让自己更清楚。是,这是使引用服务的项目的DataContract类或枚举类型可见的方法。是的,这是使引用服务的项目的DataContract类或枚举类型可见的方法。
The type or namespace name 'LogItem' does not exist in the namespace 'MyDll.LogService' (are you missing an assembly reference?)