none
message contract question RRS feed

  • Question

  • Hello - I want to set up request/response objects for my WCF service through MessageContracts.  I'm setting up my request/response as follows:

    namespace My.MessageContracts
    {
     /// <summary>
     /// Service Contract Class - GetUserRequest
     /// </summary>
     [WCF::MessageContract(WrapperName = "GetUserRequest", WrapperNamespace = "urn:my.user")]
     public partial class GetUserRequest
     {
      [WCF::MessageBodyMember(Namespace = "my.user", Name = "FirstName")]
      public string FirstName
      {
       get; set;
      }
       
      [WCF::MessageBodyMember(Namespace = "my.user", Name = "LastName")]
      public string LastName
      {
       get; set;
      }
     }
    }

    I was expecting to be able to call from the client app like this:

    var request = new GetUserRequest{ FirstName="John", LastName="Smith" };
    var response = new UserClient().GetUser(request);

    However, for some reason my service reference is getting translated so I have to call the service like this:

    //returns void
    new UserClient().GetUser("John", "Smith");

    Why is the service reference method returning void instead of the expected response?  And why does the method reference require me to pass individual parameters instead of a request object as expected?  I like the request/response design pattern but I seem to be having problems getting it to work with WCF MessageContracts?

    Tuesday, September 25, 2012 11:20 PM

Answers

  • If you want your client to have message contracts, you need to select the appropriate checkbox when adding the service reference - select "Advanced", then check the "always generate message contracts" box.

    Or if you're using svcutil, pass the /mc flag to the command line.


    Carlos Figueira

    Wednesday, September 26, 2012 4:02 AM
    Moderator
  • Carlos has answered the question regarding message contracts. Regarding the response, that depends on your ServiceContract.

    Have you defined the GetUser method on the ServiceContract as returning something? Is it a OneWay method?

    It is also possible that the service reference is expecting the Response to be passes as a byRef parameter, this is something you can also set on the svcutil.


    Juan Casanova http://jawsofdotnet.blogspot.com - My .Net babling blog

    Wednesday, September 26, 2012 6:27 AM

All replies

  • If you want your client to have message contracts, you need to select the appropriate checkbox when adding the service reference - select "Advanced", then check the "always generate message contracts" box.

    Or if you're using svcutil, pass the /mc flag to the command line.


    Carlos Figueira

    Wednesday, September 26, 2012 4:02 AM
    Moderator
  • Carlos has answered the question regarding message contracts. Regarding the response, that depends on your ServiceContract.

    Have you defined the GetUser method on the ServiceContract as returning something? Is it a OneWay method?

    It is also possible that the service reference is expecting the Response to be passes as a byRef parameter, this is something you can also set on the svcutil.


    Juan Casanova http://jawsofdotnet.blogspot.com - My .Net babling blog

    Wednesday, September 26, 2012 6:27 AM