2

I have a WCF method defined as below:

[OperationContract]
Message GetSourceData(SourceDataQuery sourceDataQuery);

And actual implementation is something like this:

public Message GetSourceData(SourceDataQuery sourceDataQuery)
    {

        IEnumerable<ExportRow> sourceData = repo.GetData();

        var customBodyWriter = new CustomBodyWriter(sourceData);
        var message = Message.CreateMessage(MessageVersion.Soap11, "GetSourceData", customBodyWriter);

        return message;
    }

SourceDataQuery object:

[MessageContract]
public class SourceDataQuery
{
    [MessageBodyMember]
    public int DataSourceId { get; set; }

    [MessageBodyMember]
    public int[] FiledIds { get; set; }

    [MessageBodyMember]
    public string Filter { get; set; }

    [MessageBodyMember]
    public string Sort { get; set; }
}

My problem is when I add this WCF service to another project and create a proxy by adding a service reference, my proxy class have a GetSourceData method but its input paramater is missing. It doesnt take any parameter.. I can see that SourceDataQuery object is generated within proxy class correctly though.

Any idea why input parameter is missing?

Otake
  • 874
  • 3
  • 8
  • 21
  • 4
    Check the WSDL. Most likely the URL that is used to reference the service has older code i.e. the method without this parameter. – amit_g Mar 01 '11 at 20:52
  • @amit_g, I've created a new project from scrath and it has the same problem. – Otake Mar 01 '11 at 21:55
  • As @amit_g says, it sounds like your service is running the incorrect version. To check this, you can try rebuilding the service and publishing under a different service path. – Greg Sansom Mar 02 '11 at 00:53
  • What happens if you thick/unthick Always generate message contracts in advanced settings of Add Service Reference dialog box? – Ladislav Mrnka Mar 02 '11 at 12:23

2 Answers2

3

Try using DataContract instead. It might solve your problem

[DataContract]
      public class SourceDataQuery
        {

            [DataMember]
            public int DataSourceId { get; set; }

            ....
        }
  • Can't use DataContract as my return type is Message which uses MessageContractAttribute. – Otake Mar 01 '11 at 21:53
  • @Otake http://msdn.microsoft.com/en-us/library/ms734675.aspx I haven't try but it seems to work... – Jean-Christophe Fortin Mar 01 '11 at 23:29
  • Thanks for your replies. I am aware that if I use Message as an input parameter and instantiate it from a SourceDataQuery object by using Message.CreateMessage it would work. I would have to change the MessageContgract attributes on SourceDataQuery to DataContract attributes though, not sure why. But what I don't understand is why SourceDataQuery as an input parameter does not work when it uses MessageContractAttribute? I have several methods and I would rather not do this conversion at my client and server. Also according to msdn it should work... – Otake Mar 02 '11 at 09:00
3

Try to wrap the serviceclient object in the IService interface, for example write:

ServiceReference1.IService1 serviceclient = new ServiceReference1.Service1Client();

instead of

ServiceReference1.Service1Client serviceclient = new ServiceReference1.Service1Client();
Cosmin
  • 21,216
  • 5
  • 45
  • 60