Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Calling WCF Service with an out parameter RSS

9 replies

Last post Mar 19, 2009 11:10 AM by ctsraj

(0)
  • dotnetmac

    dotnetmac

    Member

    28 Points

    19 Posts

    Calling WCF Service with an out parameter

    Mar 17, 2008 01:01 PM | LINK

    Hi there,

    How do i call a WCF web service which has an out parameter,

    Example:

    My service has the following signature

    public List<Entity> ListAll(string languageID, out ResultObject resultObject) { }

    When i consume this service in my SL application (code below), i only get to pass the languageID not the resultObject

    Binding binding = new BasicHttpBinding();

    EndpointAddress address = new EndpointAddress("http://localhost:5309/ContextManager/EntityService.svc");

    ContextManager.EntityService.EntityServiceClient proxy = new ListViewDataGrid.ContextManager.EntityService.EntityServiceClient(binding, address);

    proxy.ListAllCompleted += new EventHandler<ListViewDataGrid.ContextManager.EntityService.ListAllCompletedEventArgs>(proxy_ListAllCompleted);

    proxy.ListAllAsync("en-US"); // it is not asking for the ResultObject parameter.

     

    Thanx in advance

     

    WCF .NET 3.5 "Silverlight 2"

  • SpoonStomper

    SpoonStomper

    Member

    114 Points

    38 Posts

    Re: Calling WCF Service with an out parameter

    Mar 17, 2008 03:19 PM | LINK

    The idea of an out parameter is that the method will instantiate the null reference that you pass in. A web service is stateless; therefore the handle that you have on an object that goes into a webservice as a parameter will not be the same as the one that makes it into the webservice server side. The nature of this prevents out parameters.

     Instead: Create a return object that is composed of everything you need.

     Stomp it!

  • dotnetmac

    dotnetmac

    Member

    28 Points

    19 Posts

    Re: Re: Calling WCF Service with an out parameter

    Mar 17, 2008 05:01 PM | LINK

    Hey dude,

    The web service is in production environment, so i cannot change it. Please tell me how to pass an out parameter from an SL application

     

    thanx

  • SpoonStomper

    SpoonStomper

    Member

    114 Points

    38 Posts

    Re: Re: Calling WCF Service with an out parameter

    Mar 17, 2008 05:56 PM | LINK

    Hey dude,

    Oops, I wasn't aware that the proxy could handle such a thing as an out parameter. Pretty cool. Is there a reason that you are writing so much code to access the webservice. Didn't Visual Studio create a proxy class that you can instantiate and call methods on?

     StompIt!

  • SpoonStomper

    SpoonStomper

    Member

    114 Points

    38 Posts

    Re: Re: Calling WCF Service with an out parameter

    Mar 17, 2008 06:21 PM | LINK

    This seems to be an odd situation, because looking at the References.cs for a webservice, the out parameter exists in the callbacks but not in the actual calls.

  • Allen Chen – MSFT

    Allen Chen –...

    Star

    14215 Points

    1854 Posts

    Microsoft

    Re: Calling WCF Service with an out parameter

    Mar 19, 2008 07:18 AM | LINK

    Hi:

      If you use output parameters GetDataCompletedEventArgs will have relevant property for you to use. Say the parameter is called param1 you can retrieve it via:

      void proxy_GetDataCompleted(object sender, SilverlightApplication1.ServiceReference1.GetDataCompletedEventArgs e)
            {

    //e.param1

            }

    Regards

    Sincerely,
    Allen Chen
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • dotnetmac

    dotnetmac

    Member

    28 Points

    19 Posts

    Re: Re: Calling WCF Service with an out parameter

    Mar 19, 2008 08:42 AM | LINK

    Hi there,

    First of all the method in SL application doesn't even ask the out parameter.

    Say i have a service method GetData(int id, out object test), when i add a service reference, the parameters asked are just the id but not the out parameter.

  • Allen Chen – MSFT

    Allen Chen –...

    Star

    14215 Points

    1854 Posts

    Microsoft

    Re: Re: Calling WCF Service with an out parameter

    Mar 19, 2008 09:36 AM | LINK

    Hi:

      I tested it and it works fine. I guess what you really need is ref instead of out? Try this:

    GetData(int id, ref object test)

     

    Regards

    Sincerely,
    Allen Chen
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • venkatgude

    venkatgude

    Member

    2 Points

    1 Post

    Re: Re: Calling WCF Service with an out parameter

    Nov 27, 2008 08:48 AM | LINK

    Hi,

     

    How to pass ref paramer from silver light application to webservice.

    I declared a method Test(string s ,ref string test)

    How to call this method from silverlight

     

    Thanks

    Venkat 

     

  • ctsraj

    ctsraj

    Member

    14 Points

    2 Posts

    Re: Re: Calling WCF Service with an out parameter

    Mar 19, 2009 11:10 AM | LINK

    Please check the result

    void client_GetCitationCollectionCompleted(object sender, GetCitationCollectionCompletedEventArgs e)

       diseaseEvent(sender, new DiseaseEventArgs(e.OMID));

    OMID is the "out" Parameter in my WCF Service.