Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8549639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:45:46+00:00 2026-06-11T13:45:46+00:00

I’m trying to implement a WCF service as a Windows service. I’d like to

  • 0

I’m trying to implement a WCF service as a Windows service. I’d like to call it asynchronously as there are some methods that may potentially run for a couple of seconds. Following misc. tutorials (e.g. from the MSDN) didn’t really seem to do the job. I’ve got some bits working, but the data returned from the service to the client is not what I expect. Example code for the service on the server is as follows:

public interface ISomeService
{
    [OperationContract(AsyncPattern = true)]
    IAsnycResult BeginSomeMethod(string someString);

    Collection<string> EndSomeMethod(IAsnycResult asyncresult);
}

[...]

public SomeService : ISomeService
{
    public IAsyncResult BeginSomeMethod(AsyncCallback callback, object state)
    {
        // Do something...
        Collection collection = new Collection<string>{"Some Item", "Another Item"};
        return new CompletedAsyncResult<Collection<string>>(collection);
    }

    public Collection<string> EndSomeMethod(IAsyncResult asyncResult)
    {
        CompletedAsyncResult<Collection<string>> result = 
            asyncResult as CompletedAsyncResult<Collection<string>>;
        if(result != null)
        {
            return result.Data;
        }

        return result;
    }
}

I can successfully install the Windows service and also call it via the browser to see the WSDL. I can also add a reference to my “client” project to consume it – proxy classes etc. are generated without any errors. I can also call my methods like this:

[...]
    object async = new object();
    someService.BeginSomeMethod( "Some string", EndSomeMethod, async );        
[...]

The callback method looks like this:

[...]
public static void EndSomeMethod( IAsyncResult asyncResult )
    CompletedAsnycResult<Collection<string>> result = 
        asyncResult as CompletedAsnycResult<Collection<string>>;
[...]

Following this, result is null (i.e. the cast was not successful), and asyncResult does contain some properties and data, but not the expected (or wanted) string collection.

Edit
I can verify that the service method does what it is supposed to do (e.g. write to a log file, create a file or similar stuff).
/Edit

I’ve tried a couple of more approaches, but I’m somewhat confused as to what I’m doing wrong here. The examples available from Microsoft are apparently not correct (as read on some of the MSDN pages). I also found some other suggestions with event handlers etc., but was it the best way to go now?

Do I actually have to decorate service methods with the AsyncPattern = true in the OperationContract attribute? Or can I just use VS2010’s facility to generate methods for asynchronously calling the methods?

I know that there are numerous questions regarding this issue, but after spending hours on this issue I feel quite stuck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:45:47+00:00Added an answer on June 11, 2026 at 1:45 pm

    You need to call someService.EndSomeMethod(asyncResult) in your callback to get the service result. This is actually part of the standard APM pattern. You’d have to do the same thing with say a FileStream.

    Following this, result is null

    Yes, because CompletedAsnycResult only exists on the server. Your client can get any other type returned by the runtime. IAsyncResult is not part of the WCF wire-contract.

    In practice, asyncResult will be an instance of some WCF-internal class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.