none
WCF Out Parameter position change issue

    Question

  • Hi All,

    I am facing a strange issue,

    In WCF service, I have defined an operation contract with an out parameter. But when i connect this service from client side, the parameter position is changing automatically to the first position. no idea how it is happening....

    Appreciate your help...

    Thanks,
    Mads.
    Monday, May 18, 2009 7:39 PM

Answers

  • WSDL does not show the original method signature; instead, it shows the input parameters as a group and the output parameters as another group. When Add Service Reference generates client side proxy, it will download and parse WSDL, then construct a C# method with the specified input and output parameters. Since WSDL does not contain the original method signature, Add Service Reference has its own rule, which happens to be: generate out parameters first, then in parameters. Therefore the behavior you are observing is by design.

    If you would like to change the order of the parameters, you can simply modify the client proxy in Reference.cs file generated by Add Service Reference. The reason why you are getting compilation error is because client proxy in Reference.cs file is generated in one order and you are trying to use it in a different order.

    Additional Note: Although the order between in-arg and out-arg does not matter, the relative order among all in-args and the relative order among all the out-args need to be preserved. For example:
    Service: Foo(arg1, arg2, out arg3);
    Client: Foo(out arg3, arg1, arg2);  // This is OK.
    Client: Foo(arg2, arg1, out arg3);  // This is bad. It may lead to unexpected behavior at runtime.

    Thanks,
    Tao

    Thursday, May 28, 2009 1:38 AM
    Moderator

All replies

  • -> the parameter position is changing automatically to the first position.

    I think the order of parameters doesn't matter in SOA world, since those parameters will be converted into SOAP message and eventually arrive at the service side, and at the service side, it will map to the correct named parameters.

    Do you successfully call this service operation from the generated proxy at client?

    Thanks
    Marco
    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Thursday, May 21, 2009 5:29 AM
  • Thanks Marco,

    I tried in two ways,

    Using visual studio 2008  created a client and tried to access the service using 'Add service reference". When we try to call the method, because of the parameter order change, it is giving compilation error. we need to provide the out parameter in first position only when we call the method.

    And my live scenario is,

    We  have an existing windowsservice which calls the webservice and we already have an implementation which calls the method and passing parameter at the end, and it is in production. i will not be able to change the order.

    Currently only way what i am thinking is, re-write the wcf service into old ASP.NET web service.

    Apreciate your more help here...

    Thanks,
    Madhu
    Sunday, May 24, 2009 2:59 PM
  • -> Using visual studio 2008  created a client and tried to access the service using 'Add service reference". When we try to call the method, because of the parameter order change, it is giving compilation error. we need to provide the out parameter in first position only when we call the method.

    Hi Madhu, I cannot reproduce the issue you are encountering, could you please illustrate the detailed steps which could reproduce the issue you are encountering?

    Thanks
    Marco
    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Monday, May 25, 2009 3:00 AM
  • Hi Marco,

    The below method is defined in my service interface,,

           PostSubscriber(string param1, string param2, int param3, out string errMsg)

    Once we call the method as below system gives compilation error,

           PostSubscriber(param1,param2,param3,out errMsg)

    Once we change the order and provide the code like this, PostSubscriber(out errMsg, param1,param2,param3), code works fine.

    Thanks,
    Madhu
    Monday, May 25, 2009 2:30 PM
  • Could you please provide a small, complete and ready-to-run example and send it to me at v-mazho at microsoft dot com for repro? I should be able to figure out what's going on after looking into your code.

     

    Thanks

    Marco


    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Tuesday, May 26, 2009 2:28 AM
  • WSDL does not show the original method signature; instead, it shows the input parameters as a group and the output parameters as another group. When Add Service Reference generates client side proxy, it will download and parse WSDL, then construct a C# method with the specified input and output parameters. Since WSDL does not contain the original method signature, Add Service Reference has its own rule, which happens to be: generate out parameters first, then in parameters. Therefore the behavior you are observing is by design.

    If you would like to change the order of the parameters, you can simply modify the client proxy in Reference.cs file generated by Add Service Reference. The reason why you are getting compilation error is because client proxy in Reference.cs file is generated in one order and you are trying to use it in a different order.

    Additional Note: Although the order between in-arg and out-arg does not matter, the relative order among all in-args and the relative order among all the out-args need to be preserved. For example:
    Service: Foo(arg1, arg2, out arg3);
    Client: Foo(out arg3, arg1, arg2);  // This is OK.
    Client: Foo(arg2, arg1, out arg3);  // This is bad. It may lead to unexpected behavior at runtime.

    Thanks,
    Tao

    Thursday, May 28, 2009 1:38 AM
    Moderator