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 6051837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:51:42+00:00 2026-05-23T07:51:42+00:00

I implemenented the following interface in my WCF Service [ServiceContract] public interface IPrepaidService {

  • 0

I implemenented the following interface in my WCF Service

[ServiceContract]
public interface IPrepaidService
{

    [OperationContract]
    PrepaidSubscriberInfo GetSubscriberInfo(string ctn);

    [OperationContractAttribute(AsyncPattern = true)]
    IAsyncResult BeginGetSubscriberInfo(string ctn, AsyncCallback cb, object state);
    PrepaidSubscriberInfo EndGetSubscriberInfo(IAsyncResult r);



}

this way

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class PrepaidService : IPrepaidService
{

        public PrepaidSubscriberInfo GetSubscriberInfo(string ctn)
        {

            PrepaidSubscriberInfo result = null;

            try
            {
        result = new PrepaidSubscriberInfo();
        ...

            }
            catch (Exception ex) { throw new Exception(ex.ToString(), ex); }
            return result;
        }

        public IAsyncResult BeginGetSubscriberInfo(string ctn, AsyncCallback cb, object state)
        {            
            Task<PrepaidSubscriberInfo> task = Task<PrepaidSubscriberInfo>.Factory.StartNew(_ => GetSubscriberInfo(ctn), state);
            if (cb != null) task.ContinueWith(res => cb(task));
            return task;
        }

        public PrepaidSubscriberInfo EndGetSubscriberInfo(IAsyncResult ar)
        {            
            return ((Task<PrepaidSubscriberInfo>)ar).Result;
        }
}

I generated the proxy and config file:

c:\temp>svcutil http://localhost/Service.svc /async

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="MetadataExchangeHttpBinding_IPrepaidService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
            allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/Service.svc"
          binding="wsHttpBinding" bindingConfiguration="MetadataExchangeHttpBinding_IPrepaidService"
          contract="IPrepaidService" name="MetadataExchangeHttpBinding_IPrepaidService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

I’m trying to call asynchronous methods on the WCF client this way

    static void Main(string[] args)
    {

        ChannelFactory<IPrepaidServiceChannel> factory = new ChannelFactory<IPrepaidServiceChannel>("MetadataExchangeHttpBinding_IPrepaidService");
        factory.Open();
        IPrepaidServiceChannel channelClient = factory.CreateChannel();

        IAsyncResult arAdd = channelClient.BeginGetSubscriberInfo("xxx", AddCallback, channelClient);

        IAsyncResult arAdd2 = channelClient.BeginGetSubscriberInfo("xxx", AddCallback, channelClient);

        IAsyncResult arAdd3 = channelClient.BeginGetSubscriberInfo("yyy", AddCallback, channelClient);

        IAsyncResult arAdd4 = channelClient.BeginGetSubscriberInfo("yyy", AddCallback, channelClient);
        Console.WriteLine("1");



        Console.ReadKey();

    }

    static void AddCallback(IAsyncResult ar)
    {
        var result = ((IPrepaidService)ar.AsyncState).EndGetSubscriberInfo(ar);
        Console.WriteLine("Result: {0}", result);
    }

but the WCF client is always calling the GetSubscriberInfo() method on the WCF Service instead of its asynchronous version
BeginGetSubscriberInfo and EndGetSubscriberInfo. When I remove [OperationContract] PrepaidSubscriberInfo GetSubscriberInfo(string ctn);
the client calls asynchronous version.

Sorry guys for bad formatting but I couldn’t manage with this UI

  • 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-05-23T07:51:42+00:00Added an answer on May 23, 2026 at 7:51 am

    The client and service can perform/not perform async independently. The client calls async simply means from the client perspective the calls are async the service doesn’t even have to support async

    The service will prefer sync over async so if you want your service to be invoked async then remove the sync version from its version of the contract

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

Sidebar

Related Questions

Which binding should I choose to enable sessions following is my service interface: [ServiceContract(SessionMode=SessionMode.Required)]
I have following interface public interface IBuilder<T> { T Create(string param); } with many
I have a WCF webservice that has the following service contract [ServiceContract(Namespace = http://example.org)]
Given the following code: public interface IExample { ... } public abstract class BaseExample:
I have the following two methods on an interface for my service layer: ICollection<T>
I have the following base interface public interface IBaseAction { bool CanAct(...) } and
How is the following function implemented? func handle(pattern string, handler interface{}) { // ...
Is it valid and legal and to down-cast in the following case: public interface
Suppose I have the following set up: Public Interface IA Property Name() Property Id()
Given the following code public interface Foo<T> { T get(); } @Remote public interface

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.