我已经为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文档。
任何人都有经验试图做到这一点?或者我在做什么错误的任何想法?
WCF服务此刻在其他地方使用吗? – glosrob