1

I am defining a number of functions in my client, as an example

[OperationContract]
List<CustomObject> GetObject(string id);

When trying to call this function from my interface if I try:

List<CustomObject> result = cvs.GetObject(5); I get an error, instead what I must do is CustomObject[] result = cvs.GetObject(5);

One other example is when I define a message:

[MessageContract]
public class TestRequest
{
     [MessageBodyMember]
     public Int64 Id;

     [MessageBodyMember]
     public int row;
}

and a function for my Interface:

[OperationContract]
ResponseMessage GetMessage(TestRequest req);

When I try to use this much in the same manner:

TestRequest req = new TestRequest();
req.Id = 2;
req.row = 1;
ResponseMessage resp = cvs.GetMessage(req);

I get the there is no overload for method that takes one argument message.

Below is the relevant part of the reference file created by

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
ResponseMessage MyService.GetMessage(TestRequest request)
{
    return base.Channel.GetMessage(request);
}

    public string GetMessage(long Id, int row, out long Length, out string Message, out System.IO.MemoryStream ReportMemoryStream)
    {
        TestRequest inValue = new ResponseMessage();
        inValue.Id = Id;
        inValue.row= row;
        ResponseMessage retVal = ((MyService)(this)).GetMessage(inValue);
        Length = retVal.Length;
        Message = retVal.Message;
        ReportMemoryStream = retVal.ReportMemoryStream;
        return retVal.FileName;
    }

Why is this disconnect between client and wfc service happen, and how can I solve it.

dearn44
  • 3,198
  • 4
  • 30
  • 63

2 Answers2

2

There is a question on here already with some answers that explain the 'disconnect' as you call it between the client and the service:

Why does WCF return myObject[] instead of List like I was expecting?

Hopefully this is what you are after.

Community
  • 1
  • 1
Martin Davies
  • 169
  • 13
  • This solves the issue with lists, but not the issue with my custom message. – dearn44 Mar 03 '16 at 15:27
  • Any reason why you are using a MessageContract rather than a DataContract? Also out of interest, if you are using Visual Studio, what is the IDE expecting the method definition to be? – Martin Davies Mar 03 '16 at 15:49
  • No idea actually, I simply wanted to also use MessageContract once since I am trying to learn as many secrets as I can .) Also updated the question, I believe it will answer your other question. – dearn44 Mar 03 '16 at 16:21
  • I have to admit, I've never really used MessageContract so don't know much about it (except that it's something to do with controlling the headers as well as the data) - hopefully somebody else will come by and explain! I would be tempted to use DataContract in this case and see if that helps at all. – Martin Davies Mar 03 '16 at 17:03
2

Did you update the service reference after your last change of the method? Looks like the proxy he generated isn't up to date.

Chris Schmitz
  • 390
  • 4
  • 15