开发者

Parameters or Arguments in WCF service

开发者 https://www.devze.com 2023-01-19 03:44 出处:网络
A wcf service accessing an SQL database: private void GetImagesDataFromDB(int imageIndex, int **extraParam**)

A wcf service accessing an SQL database:

    private void GetImagesDataFromDB(int imageIndex, int **extraParam**)
    {
        ServiceReference1.DbServiceClient webService =
            new ServiceReference1.DbServiceClient();
        webService.GetSeriesImagesCompleted += new EventHandler<ServiceReference1.GetSeriesImagesCompletedEventArgs>(webService_GetSeriesImagesCompleted);
        webService.GetSeriesImagesAsync(imageIndex);
    }

the GetImageSeriesCompleted EventHandler is here:

    void webService_GetSeriesImagesCompleted(object sender,
        TheApp.ServiceReference1.GetSeriesImagesCompletedEventArgs e)
    {
        if (e.Result != null)
        {
            if (**extraParam** == 1)
            {
                lstImages = e.Result.ToList();

            }
            else 
            {
                // do something else
            }
        }
    }

The service itself is like this:

   public List<Image> GetSeriesImages(int SeriesId)
    {
        DataClassDataContext db = new DataClassDataContext();
        var images = from s in db.Images
                     where s.SeriesID == SeriesId
                     select s;
        return images.ToList();
    }

What is the best way to pass the extraParam to the service completed E开发者_C百科ventHandler? I need this to direct my service return to a proper UI control.

Thanks.


You've probably figured this out by now, but the webService.GetSeriesImagesAsync() call has a second overload, namely, webService.GetSeriesImagesAsync(int seriesId, object userState). That second parameter will get passed into the callback as e.UserState. A good pattern is actually to pass a lambda callback as the userstate, and execute that in the webService_GetSeriesImagesCompleted() method.

0

精彩评论

暂无评论...
验证码 换一张
取 消