2013-01-24 31 views
1

我已經爲Dynamics CRM 2011編寫了一個插件,用於調用託管在不同服務器上的WCF服務。下面是我的插件中的代碼。在插件的類庫中,我沒有使用服務引用,但使用svcutil.exe來生成WCF客戶端。從動態crm 2011插件調用WCF服務

var binding = new BasicHttpBinding(); 
binding.Name = "BasicHttpBinding_IMyService"; 
binding.Security.Mode = BasicHttpSecurityMode.None; 
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; 
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 
var endpoint = new EndpointAddress("http://test/MyService.svc"); 
ChannelFactory<IMyService> factory = new ChannelFactory<IMyService>(binding, endpoint); 
IMyService channel = factory.CreateChannel(); 
channel.InsertTest(testobject); 

我收到以下錯誤:

'System.Threading.Tasks.Task`1 [System.Int32]' 不能被序列化。考慮使用DataContractAttribute屬性標記它,並使用DataMemberAttribute屬性標記要序列化的所有成員。如果類型是一個集合,請考慮使用CollectionDataContractAttribute來標記它。有關其他支持的類型,請參閱Microsoft .NET Framework文檔。

任何人都有經驗試圖做到這一點?或者我在做什麼錯誤的任何想法?

+0

WCF服務此刻在其他地方使用嗎? – glosrob

回答

0

您得到的錯誤是您正在發送的對象的序列化。檢查你的testobject是否有一個Task屬性。如果有,請考慮在序列化期間忽略它。 See this SO post.

0
  1. 確保服務設置正確。幾個月前我曾經爲此哭過血。 Google爲「在VS 2010中爲REST設置基本的WCF Web服務」,您可能會在WordPress博客中受到關注,我將在其中解釋該方法。 (不想在這裏自我推銷,我希望別人有這個博客之前我自己解決了這個問題。)

  2. 顯示您用來連接到服務的代碼。當我明天開始工作時,我可以與我比較並找出任何不同之處。我記得我有這個序列化問題,但我不知道我們是如何殺死它的。但是,我們做了,不知何故。 (並檢查Daryl的提示是否有效。它可以)