2011-04-19 63 views
3

我無法在引用.NET 4.0的System.ServiceModel和System.ServiceModel.Web庫時實例化WebHttpBinding類。引用3.5庫時,我可以實例化這個類。該文件說WebHttpBinding在4.0中支持,所以我做錯了什麼?.NET 4.0中的WebHttpBinding?

new ChannelFactory<INotesService> 
(new WebHttpBinding(), 
new EndpointAddress("http://localhost:3380/Service.svc")) 

當我按下CTRL +。在WebHttpBinding上它沒有找到它的名字空間。

http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx

+0

檢查項目屬性中的目標框架選項,你確定目標框架是.Net 4嗎? – 2011-04-19 05:11:52

回答

4

是的,這絕對是在.NET 4中,它的命名空間沒有改變或類似的東西。

有趣的是,它從System.ServiceModel.Web.dll移動到System.ServiceModel.dll,類型從System.ServcieModel.Web.dll永久轉發。所以,你應該能夠將任何3.5項目轉換到4.0,並讓它工作。

所以,你的項目肯定會工作。如果目標框架建議不起作用,您可以粘貼您獲得的錯誤消息嗎?

+0

該項目沒有設置爲Target Framework .NET 4,這是VS 2010項目中的奇怪之處。謝謝。 – 2011-04-19 13:22:41