由于类名错误,Wcf 服务元数据无法访问
目前我正在编写一个WCF 服务。该服务返回一个对象,其类型属于名为“System”的用户定义类。代码片段如下:
[DataContract]
public class System
{
// ....
}
[ServiceContract]
public interface DemoServcie
{
[OperationContract]
System GetSystem();
}
但是我在运行wcf服务时遇到了问题。错误信息是:
添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。
c:\Users\xxx\AppData\Local\Temp\Test Client Projects\10.0\6909a900-97bd-4efb-aae9-6c2e9b23e4b9\Client.cs(321,50):错误CS0426:类型名称“运行时”类型“Demo.DomainModel.System”中不存在 c:\Users\xxx\AppData\Local\Temp\Test Client Projects\10.0\6909a900-97bd-4efb-aae9-6c2e9b23e4b9\Client.cs(264,18):错误CS0426:类型名称“运行时”不存在在类型“Demo.DomainModel.System”中 ...
但是如果我将类名“System”重命名为其他名称,例如“System1”,就可以了。我猜想“System”是保留的命名空间名称,无法使用。这是真的吗?
Currently I write a WCF service. The service returns an object whose type is of a user-defined class named "System". The code snippet is as follows:
[DataContract]
public class System
{
// ....
}
[ServiceContract]
public interface DemoServcie
{
[OperationContract]
System GetSystem();
}
But I encoutered a problem when running the wcf service. The error message is:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
c:\Users\xxx\AppData\Local\Temp\Test Client Projects\10.0\6909a900-97bd-4efb-aae9-6c2e9b23e4b9\Client.cs(321,50) : error CS0426: The type name 'Runtime' does not exist in the type 'Demo.DomainModel.System'
c:\Users\xxx\AppData\Local\Temp\Test Client Projects\10.0\6909a900-97bd-4efb-aae9-6c2e9b23e4b9\Client.cs(264,18) : error CS0426: The type name 'Runtime' does not exist in the type 'Demo.DomainModel.System'
...
But if I rename the class name "System" to other names such as "System1", it is OK. I guess that the "System" is a reserved namespace name and cannot be used. Is it true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您看到以下行时:
问题是编译器在您刚刚定义的 System 类中查找运行时类型,而不是在系统命名空间中。
如果你把 global: 放在 System.Runtime 前面,它至少会编译。
查看以下内容,其中说明了 System 类的确切问题: 如何:使用全局命名空间别名
When you have the line:
The problem is that the compiler looks for the Runtime type in the System class you just defined, not in the System Namespace.
If you put global: in front of the System.Runtime, it will at least compile.
Have a look at the following which illustrates your exact problem with a System class: How to: Use the Global Namespace Alias