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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:43:17+00:00 2026-05-15T20:43:17+00:00

I am writing the client side for a WCF service that supports both synchronous

  • 0

I am writing the client side for a WCF service that supports both synchronous and asynchronous calls without having to implement 5-6 different methods in channel for each method in the contract.

I have a base interface (IServiceClient) and a generic class based on this interface type (ServiceClient) as follows:

public interface IServiceClient { /* nothing here -- just for casting purpose */ }

public abstract class ServiceClient<TChannel> : ClientBase<TChannel> where TChannel : class, IServiceClient
{
    ....

    public T SyncCall<T>(string method, object[] args)
    {
        ....
        return (T)...
    }

    public ServiceCall<T> AsyncCall<T>(string method, object[] args)
    {
        return new ServiceCall<T>(this, method, args);
    }

    ....

    public class ServiceCall<T>
    {
        public ServiceCall(RemoteServiceClient<TChannel> service, string method, object[] args)
        {
            ...
        }

        ...

        public PageAsyncTask CreatePageAsyncTask(Action<T> onSuccess, Action<Exception> onFailure)
        {
            return new System.Web.UI.PageAsyncTask(...);
        }
    }
}

Also, have another interface (actual contract) extending the base interface and a specific implementation of the ServiceClient class based on the derived interface as follows:

[ServiceContract]
public interface IMyServiceClient : IServiceClient
{
    ....

    [OperationContract]
    string GetWhatever(int index);
    [OperationContract]
    IAsyncResult BeginGetWhatever(int index, System.AsyncCallback callback, object asyncState);
    string EndGetWhatever(System.IAsyncResult result);

    ....
}


public partial class MyServiceClient : ServiceClient<IMyServiceClient>
{
    ....

    public string GetWhatever(int index)
    {
        return SyncCall<string>("GetWhatever", new object[] { index });
    }
    public ServiceCall<string> GetWhateverAsync(int index)
    {
        return AsyncCall<string>("GetWhatever", new object[] { index });
    }

    ....
}

I try to call the GetWhatever(int) method asynchronously in my control as follows:

public class MyWebControl : WebControl
{
    private void HandleFailure(System.Exception e) { .... }
    public void CallService<T>(ServiceClient<IServiceClient>.ServiceCall<T> func, System.Action<T> onSuccess, System.Action<Exception> onFailure)
    {
        this.Page.RegisterAsyncTask(func.CreatePageAsyncTask(onSuccess, onFailure ?? (e => this.HandleFailure(e))));
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        ....

        var client = new MyServiceClient(/*whatever*/);
        client.Open();
        CallService(client.GetWhateverAsync(index), this.OnResult, this.OnError);

        ....
    }

    public void OnResult(string result) { .... }
    public void OnError(Exception e) { .... }
}

I get 2 compilation errors:

Error 1 The best overloaded method match for 'MyWebControl.CallService<string>>(IServiceClient>.ServiceCall<string>, System.Action<string>, System.Action<System.Exception>)' has some invalid arguments
Error 2 Argument 1: cannot convert from 'ServiceClient<IMyServiceClient>.ServiceCall<string>' to 'ServiceClient<IServiceClient>.ServiceCall<string>'

Apparently the compiler can’t seem to figure out that IMyServiceClient extends IServiceClient. I understand that the interface inheritance doesn’t work like class inheritance; but I am not sure how to work around this compiler error. I already tried adding a new ServiceCall implementation inside MyServiceClient class to extend that in base — but the compiler error hasn’t changed.

BTW, if I change my ServiceClient implementation to base off of IMyServiceClient, it works. Also, calling just client.GetWhatever(index) (which calls SyncCall method) compiles and works just fine.

Any idea of what’s going on or what the compiler is looking for would help. Thanks.

  • 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-15T20:43:18+00:00Added an answer on May 15, 2026 at 8:43 pm

    Solved it by changing the CallService method in my control:

    public void CallService<TChannel, T>(ServiceClient<TChannel>.ServiceCall<T> func, System.Action<T> onSuccess, System.Action<Exception> onFailure) where TChannel: class, IServiceClient
    { 
        this.Page.RegisterAsyncTask(func.CreatePageAsyncTask(onSuccess, onFailure ?? (e => this.HandleFailure(e)))); 
    } 
    

    Thx.

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

Sidebar

Related Questions

I am writing a client side HTML page with jQuery that calls web services
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
I have an old client side application that is writing to named pipes using
I'm writing a piece of client-side javascript code that takes a function and finds
I'm writing a small multithreaded client-side python application that contains a small webserver (only
I'm writing a web-service for Android. The client side will be coded in JAVA
I'm writing an application with some client-side JS that I use to update the
I have a need to connect to a WCF service I wrote without having
Typically when writing a web-app we want to perform validation on both client side
What is a decent IDE for developing JavaScript, I'll be writing both client side

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.