2013-01-24 28 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的提示是否有效。它可以)