【发布时间】:2010-03-24 13:15:08
【问题描述】:
我有一个小型测试网络服务来模拟我在现实世界应用程序中注意到的一些奇怪的东西。由于演示显示与应用程序相同的行为,为了简洁起见,我将使用演示。
简而言之,我的服务接口文件如下所示(如您所见,它是 VS2008 创建的默认 WCF 服务,但我在底部添加了一个新的公共方法(GetOtherType())和两个新类(SomeOtherType 和 SomeComplexType ). SomeOtherType 管理 SomeComplexType 类型的通用 List
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WCFServiceTest
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[OperationContract]
SomeOtherType GetOtherType();
}
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
[DataContract]
public class SomeOtherType
{
public List<SomeComplexType> Items { get; set; }
}
[DataContract]
public class SomeComplexType
{
}
}
我的服务实现如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WCFServiceTest
{
public class Service1 : IService1
{
#region IService1 Members
public string GetData(int value)
{
throw new NotImplementedException();
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
throw new NotImplementedException();
}
#endregion
#region IService1 Members
public SomeOtherType GetOtherType()
{
throw new NotImplementedException();
}
#endregion
}
}
我遇到的问题是,如果我在 ASP.NET Web 应用程序中包含对此服务的服务引用,我无法通过智能感知看到 SomeComplexType。错误与找不到类型或命名空间有关。但是,可以找到 SomeOtherType(我假设该类型是公共方法之一的返回类型)。
如果我的一个公共方法(返回类型或参数)的方法签名中没有该类型,我是否认为我不能从 WCF 服务公开该类型?如果是这样,我将如何遍历客户端上 SomeOtherType 实例中的 Items?
非常感谢,我希望这很清楚。
西蒙
【问题讨论】:
-
这确实很奇怪。为什么要在一个地方定义数据合同和服务本身?另外,这是在 SVC 文件中还是在某个单独的 .cs 文件中?
标签: wcf service intellisense