-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor System.Servicemodel.ClientBase to have non-generic base #13940
Comments
Can you provide more details on this? I'm not sure I understand. Which method cannot you not write? AuthorizeRequest method that you call above? Or CallAsync method? |
When making a call to the extension like: var client = new ProfileServiceClient();
UserProfile userProfile =
await client.CallAsync(c => c.UserProfile(), authorization, response.ClientDisconnectedToken); The compiler generates the following error at the call to the extension function:
While intellisense shows the extension method as available for ProfileServiceClient, I'm assuming the compiler isn't able to infer the type TChannel (At least not in VS 2012) because there is no parameter associated with that type. I need to be able to access public static async Task<T> CallAsync<TClient, T>(this TClient wcfClient, Func<TClient, T> predicate, IAuthorizationState authorization, CancellationToken cancellationToken) where TClient : ClientBase The problem with inferring the type of TChannel then goes away. In general I have found it a useful design pattern to place all non-generic members of a generic class in non-generic base, for just this reason. |
I haven't tested this, but wouldn't something along these lines work: public static class ExtensionMethods
{
public static async Task<T> CallAsync<TChannel, T>(this ClientBase<TChannel> wcfClient, Func<TChannel, T> predicate, IAuthorizationState authorization, CancellationToken cancellationToken)
{
var uri = wcfClient.Endpoint.Address.Uri; // Endpoint exists on ClientBase<TChannel>
// In theory the following could throw a runtime cast exception if the class derived from ClientBase<T>
// didn't implement the service interface, but then you would have a pretty broken client anyway and your
// problems are likely much bigger!!
TChannel channel = (TChannel)wcfClient;
T result = predicate(channel);
}
} |
No, it isn't able to infer the TChannel from the wcfCient parameter. |
Thanks @rcollette . I have reopened this issue in the new WCF repo as Issue dotnet/wcf#42 where we can continue to discuss this. |
Add commit file reference to 1.1 Preview 1 relnotes
Remove the newly added test again.
The following is an example of a generic extension method I would like to write, but cannot because
ClientBase<T>
does not inherit from a base class containing the non generic members. It would be very helpful ifClientBase<T>
was refactored intoClientBase<T>:ClientBase
The text was updated successfully, but these errors were encountered: