I’ve recenlty been doing some work with Sql Server Reporting Services talking to a WCF Service. This isn’t quite as easy as it sounds. The first thing you need to do is specify a new data source as an XML based source.
You then specify a nice request and response as with any message based WCF service:
[MessageContract(IsWrapped = true)]
public class DataRequest
private string _fieldA = string.Empty;
private string _fieldB = string.Empty;
private string _fieldC = string.Empty;
The response looks something like this:
public class DataReponse
private data _data;
And the data object looks like this:
public class Data
private string _field1;
private string _field2;
private string _field3;
// Ctor, Getters and setters excluded
Voila you’re done… Or are you?!?
I found quite a nasty gotcha in doing this. My request class was only being partially populated everytime I did a request. I checked the attributes on the service and classes, I used TCP Trace to make sure the values were actually crossing the wire (which they were), but still the request wasn’t being populated properly.
I even asked my pal [insert favourite search engine here] but couldn’t fnd anything on it. So I started playing around with the fields in the report and low 2 of the 6 request params were now being populated! What had changed? The ordering. After a few more trial and errors I found the problem. The parameters from the report have to be sent in alphabetic order, otherwise for some reason the request doesn’t deserialise properly.