1
votes

I have written a plugin for Dynamics CRM 2011 that calls a WCF service hosted on a different server. Below is the code in my plugin. In the class library for the plugin I have not used a service reference but used svcutil.exe to generate a WCF client.

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);

I am getting the following error:

'System.Threading.Tasks.Task`1[System.Int32]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

Anyone had experience trying to do this? Or any ideas on what I am doing wrong?

2
Is the WCF service in use elsewhere at the moment?glosrob

2 Answers

0
votes

The error your getting is with the serialization of the object you're sending. Check to see if your testobject has a Task property. If it does, consider ignoring it during serialization. See this SO post.

0
votes
  1. Make sure the service is set up correctly. I cried blood a few months ago doing that. Google for "Setting up a basic WCF web service for REST in VS 2010" and you'll probably get a hit on WordPress blog where I explain the approach. (Not trying to self-promote here. I wish someone else had that blog before I resolved the issue myself. Really.)

  2. Show the code that you're using to connect to the service. When I get to work tomorrow, I can compare with mine and find any difference. I remember that I had this serialization issue but I'm not sure how we killed it. But we did, somehow. (And check if Daryl's hint works. It could.)