我有一個小型測試Web服務來模擬我在一個真實世界的應用程序中注意到的奇怪事情。由於演示顯示與應用程序相同的行爲,因此我將使用該演示以簡化操作。我可以看到它是由VS2008創建的默認WCF服務,但我在底部添加了一個新的公共方法(GetOtherType())和兩個新類(SomeOtherType和SomeComplexType)。SomeOtherType管理型SomeComplexType的泛型列表WCF服務未公開的類型
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應用程序,我可以沒有通過intellisense看到SomeComplexType。錯誤與類型或名稱空間無關。但是,可以找到SomeOtherType(我假設該類型是一個公共方法的返回類型)。
我是否正確思考如果該類型沒有在我的一個公共方法(返回類型或參數)的方法簽名中出現,我無法公開WCF服務的類型?如果是這樣,我將如何迭代客戶端上的SomeOtherType實例中的Items?
很多謝謝,我希望這很清楚。
西蒙
確實很奇怪。你爲什麼要在一個地方定義數據合同和服務本身?此外,這是在SVC文件或一些單獨的.cs文件? – Slavo 2010-03-24 13:39:01