tags:

views:

101

answers:

3

Hi,

I am using Silverlight, WCF combination.

Currently, I am facing one problem with service response.

I am using request response service type.

I have 100 Items and i am going to call 100 services to fetch it's properties.

foreach (ItemDto item in items)
{

   ServiceCall(); 
   ServiceSendCount++;
}


private void OnServiceCallCompleted(.....)
{
    ServiceReceiveCount++;
}

If i am sending 5 service calls then it returns with 5*5 = 25 responses. same with as i am sending 10 service calls then it returns with 10*10 = 100 responses.

I am not able to figure out what was the problem....

Can anyone please shed some light on this?


Mahesh

+2  A: 

Can't tell from the code as you didn't show the ServiceCall() function but numbers suggest you are reusing the same proxy object and adding the OnServiceCallCompleted event handler every time you make a request. If you add the same event handler multiple times it is going to fire multiple times and the completed event handler is per proxy object not per request.

Try creating a new proxy object for each request and seeing if you still get multiple responses.

Maurice
A: 

Hi Maurice, Thanks for the response.. :D

Please find herewith the service call method. I agree that each and every time i am sending OnServiceCallCompleted ..

foreach (ItemDto item in items)
{

   itemPropertyService.GetItemProperties([parameters] , OnServiceCallCompleted);
   ServiceSendCount++;
}


private void OnServiceCallCompleted(.....)
{
    ServiceReceiveCount++;

    /* here contains my logic to process the response
       If it cames mulriple time then my logic will down 
    */
}

Can you please let me know the solution for same. As the change in the service is not possible right now...

Thanks, Mahesh

@Mahesh: you really need to learn this, please!! In order to properly show code, you need to highlight your lines of code and then press the "code" button (010 101) on the toolbar, or hit Ctrl-K on your keyboard. Only then is code nicely and properly formatted
marc_s
A: 

Hi Maurice,

Your thought was correct. Thanks :D But it will create the problem of response time.

Suppose i am going to send the request for 100 items at a time.

In My first approch, i will get the first 100 responses with correct data in withing 5-10 sec.

ItemPropertyService itemPropertyService = new ItemPropertyService();
foreach (ItemDto item in items) 
{
     itemPropertyService.GetItemProperties([parameters] , OnServiceCallCompleted);  
     ServiceSendCount++; 
}

(Problem as i discussed it is going to send me 100 X 100 responses which leads to the timeout)

In Second Approch, (As per u have suggested)

foreach (ItemDto item in items) 
{
      ItemPropertyService itemPropertyService = new ItemPropertyService();
      itemPropertyService.GetItemProperties([parameters] , OnServiceCallCompleted);
      ServiceSendCount++; 
}

I am getting same responses as of request, but it will take time near about 2 min.

Actually, I am not able to figure out the problem of time consuming. As our requests are very huge it will really going to take time.

Do you know about this that how to solve this problem?

I am just near to solve my problem.

Mahesh...

@Mahesh: you should edit your original post, instead of answering your own questions with additional information......
marc_s
@Mahesh: in order to properly show code, you need to highlight your lines of code and then press the "code" button (010 101) on the toolbar, or hit Ctrl-K on your keyboard. Only then is code nicely and properly formatted
marc_s