dipdip

Can I use the AsyncPattern if I have overloads for the begin method in the service contract that are tagged with the name property I am getting an Argurment exception when I call Open on my serviceHost object.

System.ArgumentException was caught
Message="An item with the same key has already been added."
Source="mscorlib"
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.ServiceModel.Dispatcher.OperationSelectorBehavior.MethodInfoOperationSelector..ctor(ContractDescription description)
at System.ServiceModel.Dispatcher.OperationSelectorBehavior.System.ServiceModel.Description.IContractBehavior.ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()

I am not sure if the problem is with the async pattern, or something else.
Code Block

[OperationContract(AsyncPattern = true, Name = "BeginOperationOne")]

IAsyncResult BeginOperation(string name, AsyncCallback callback, object state);

[OperationContract(AsyncPattern = true, Name = "BeginOperationTwo")]
IAsyncResult BeginOperation(string name, string value, AsyncCallback callback, object state);

int EndOperation(IAsyncResult result);





Re: Windows Communication Foundation (Indigo) AsyncPattern with overloads in service contract

David So - MSFT

As you found out, this is not currently possible. Each Begin/End is tightly coupled so you cannot share the 'EndOperation' in this way.

The exception error message is not very helpful though. I'll raise this as an issue with our team, to see what we can do to improve this (consider improving the error msg or supporting begin/end overloading) in a future release. No guarantees though!