locked
Regarding Out Parameters in WCF RRS feed

  • Question

  • Hi I have created a wcf service ,in which i am using out keyword for returning values.Is there any interoperability issue while consumer is other than dotnet apps.???? If there how can i resolve that???

    I am attaching piece of code,can anyone help me plzzzz.....

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace HelloService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HelloService" in both code and config file together.
        public class HelloService : IHelloService
        {
            public void GetMessage(out string name)
            {
                name= "Hello Welcome...";
            }
        }
    }





    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace HelloService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IHelloService" in both code and config file together.
        [ServiceContract]
        public interface IHelloService
        {
            [OperationContract]

            void GetMessage( out string name);
        }
    }

    Best Regards,

    Latheesh K


    Latheesh K Contact No:+91-9747369936


    • Edited by La07K Monday, July 4, 2016 5:44 AM
    Monday, July 4, 2016 5:44 AM

Answers

All replies

  • string GetMessage( );  //with a return value

    That's what it should be. I don't even know where you came up with some 'out' parm. Surely, you have seen no WCF example doing it, an out parm.

    The universal data representation across platforms is primitive string, XML or Json.

    Monday, July 4, 2016 7:48 AM



  • MYserver Code is like:


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace HelloService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HelloService" in both code and config file together.
        public class HelloService : IHelloService
        {
            public void GetMessage(out string name)
            {
                name= "Hello Welcome...";
            }
        }
    }





    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace HelloService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IHelloService" in both code and config file together.
        [ServiceContract]
        public interface IHelloService
        {
            [OperationContract]

            void GetMessage( out string name);
        }
    }



    MY client C#:

      Hello.HelloServiceClient hc = new Hello.HelloServiceClient();

      string s= hc.GetMessage();// Note this GetMesssage function return type is Void in server,but it return stringthe use of out keyword 
    here m getting output as expected.But my question is if it is a java client.how will it behave
    • Edited by La07K Monday, July 4, 2016 9:16 AM
    Monday, July 4, 2016 9:12 AM
  • string s= hc.GetMessage();// Note this GetMesssage function return type is Void in server,but it return stringthe use of out keyword 
    here m getting output as expected.But my question is if it is a java client.how will it behave

    As long as it primitive string, XML or Json, then you got no problem. Of course XML and Json are string, right? 

    Monday, July 4, 2016 4:53 PM
  • Yes...Thanks

    Latheesh K Contact No:+91-9747369936

    Tuesday, July 5, 2016 7:36 AM
  • Hi Latheesh K,

                                You are implementing code correct  and you are getting value from void method ,because you are using out parameters in method.

    Ref and out use to return multiple output from any method for more details you can visit my blog:-

    https://bikeshsrivastava.blogspot.in/2016/06/part-22what-is-ref-and-out-in-c.html

    Tuesday, July 5, 2016 7:46 AM