Skip to main content

Microsoft Silverlight

Answered Question Calling WCF Service with an out parameterRSS Feed

(0)

dotnetmac
dotnetmac

Member

Member

28 points

19 Posts

Calling WCF Service with an out parameter

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

 

SpoonStomper
SpoonSto...

Member

Member

114 points

37 Posts

Re: Calling WCF Service with an out parameter

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

Member

28 points

19 Posts

Re: Re: Calling WCF Service with an out parameter

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
SpoonSto...

Member

Member

114 points

37 Posts

Re: Re: Calling WCF Service with an out parameter

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
SpoonSto...

Member

Member

114 points

37 Posts

Re: Re: Calling WCF Service with an out parameter

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 Ch...

Star

Star

13856 points

1,800 Posts

Re: Calling WCF Service with an out parameter

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

Member

28 points

19 Posts

Re: Re: Calling WCF Service with an out parameter

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 Ch...

Star

Star

13856 points

1,800 Posts

Answered Question

Re: Re: Calling WCF Service with an out parameter

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

Member

2 points

1 Posts

Re: Re: Calling WCF Service with an out parameter

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

Member

14 points

2 Posts

Re: Re: Calling WCF Service with an out parameter

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities