Otake
Otake

Reputation: 894

Method parameter is missing in WCF proxy class

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?

Upvotes: 2

Views: 1803

Answers (2)

Mohammed el Shafaey
Mohammed el Shafaey

Reputation: 31

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

Upvotes: 3

Jean-Christophe Fortin
Jean-Christophe Fortin

Reputation: 748

Try using DataContract instead. It might solve your problem

[DataContract]
      public class SourceDataQuery
        {

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

            ....
        }

Upvotes: 3

Related Questions