Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Multiple calls to same wcf service method from Silverlight application

Multiple calls to same wcf service method from Silverlight application

Scheduled Pinned Locked Moved WPF
csharpwcfdesignhelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pankaj Chamria
    wrote on last edited by
    #1

    I am using a Silverlight enabled WCF Service with the following attribute:

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    It has a method say

    [OperationContract]
    public IEnumerable GetAllEntities();

    Sometimes I want to call this method multiple times within short span of time.. as WCF calls from Silverlight have to be asynchromous, the second call ends up getting called before the first one returned with the results. This results into the UserState getting corrupted. I find that the UserState of one of the calls gets overwritten by that of another call. I find this problem when the calls return and I extract the UserState from the EventArgs. This seems to be a concurrency problem. I know we should avoid design which causes such multiple calls in Silverlight, but in some cases you just have to. Is there any workaroung/ solution to this problem?

    Pankaj Chamria

    A M B 3 Replies Last reply
    0
    • P Pankaj Chamria

      I am using a Silverlight enabled WCF Service with the following attribute:

      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

      It has a method say

      [OperationContract]
      public IEnumerable GetAllEntities();

      Sometimes I want to call this method multiple times within short span of time.. as WCF calls from Silverlight have to be asynchromous, the second call ends up getting called before the first one returned with the results. This results into the UserState getting corrupted. I find that the UserState of one of the calls gets overwritten by that of another call. I find this problem when the calls return and I extract the UserState from the EventArgs. This seems to be a concurrency problem. I know we should avoid design which causes such multiple calls in Silverlight, but in some cases you just have to. Is there any workaroung/ solution to this problem?

      Pankaj Chamria

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Well, call the second service once the first one executes. No other choice.

      The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

      1 Reply Last reply
      0
      • P Pankaj Chamria

        I am using a Silverlight enabled WCF Service with the following attribute:

        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

        It has a method say

        [OperationContract]
        public IEnumerable GetAllEntities();

        Sometimes I want to call this method multiple times within short span of time.. as WCF calls from Silverlight have to be asynchromous, the second call ends up getting called before the first one returned with the results. This results into the UserState getting corrupted. I find that the UserState of one of the calls gets overwritten by that of another call. I find this problem when the calls return and I extract the UserState from the EventArgs. This seems to be a concurrency problem. I know we should avoid design which causes such multiple calls in Silverlight, but in some cases you just have to. Is there any workaroung/ solution to this problem?

        Pankaj Chamria

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Just asking....the UserState you refer to is your object right? Like Abhinav S mentioned, you need to chain the asynchronous calls.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • P Pankaj Chamria

          I am using a Silverlight enabled WCF Service with the following attribute:

          [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

          It has a method say

          [OperationContract]
          public IEnumerable GetAllEntities();

          Sometimes I want to call this method multiple times within short span of time.. as WCF calls from Silverlight have to be asynchromous, the second call ends up getting called before the first one returned with the results. This results into the UserState getting corrupted. I find that the UserState of one of the calls gets overwritten by that of another call. I find this problem when the calls return and I extract the UserState from the EventArgs. This seems to be a concurrency problem. I know we should avoid design which causes such multiple calls in Silverlight, but in some cases you just have to. Is there any workaroung/ solution to this problem?

          Pankaj Chamria

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          You mean the UserState on the server, right? Either you need to write the service so that it can cope with being run concurrently, or wrap the content of that method with lock(UserState){ ... }. (You don't want to use [Synchronized] because it should be able to run concurrently for different users, even if making it work concurrently for the same one is too hard.) Obviously, the first way is preferred. I'm guessing your method is actually not just a 'GetAllXxx' but instead updates some server state, because there should be no problem with doing multiple gets in parallel, and also you would not need to call that multiple times (the result could be cached). Can you explain a bit more about what the service method is doing and why you need to call it multiple times? I would expect that it would be possible to bundle the requests up into a single service call in some way, reducing network traffic as well as reducing your concurrency issues. But you should still write a robust service regarding concurrency.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups