i have the following Service Contract
[ServiceContract]
public interface IDataService
{
[OperationContract]
void UpdateProcessingState(ActionState state);
}
however i want to allow the client ChannelFactory
access to an Asynchronous pattern so I've inherited the above contract with
[ServiceContract]
public interface IDataServiceClient : IDataService
{
[OperationContract(AsyncPattern = true, IsOneWay = true)]
IAsyncResult BeginUpdateProcessingState(ActionState state, AsyncCallback asyncCallback, object obj = null);
void EndUpdateProcessingState(IAsyncResult r);
}
I was hoping this would allow me to use the following on the server without having to implement the async stubs, ie
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataService : IDataService
{
public void UpdateProcessingState(ActionState state)
{
}
//public IAsyncResult BeginUpdateProcessingState(ActionState state, AsyncCallback asyncCallback, object obj = null)
//{
// throw new NotImplementedException();
//}
//public void EndUpdateProcessingState(IAsyncResult r)
//{
// throw new NotImplementedException();
//}
}
While giving the clients ChannelFactory
access to the async methods
ChannelFactory = new ChannelFactory<IDataServiceClient>(GetBinding(), GetEndpoint());
ChannelFactory.Endpoint.Behaviors.Add(new ProtoEndpointBehavior());
_proxy = ChannelFactory.CreateChannel();
Proxy.BeginUpdateProcessingState(state, ar =>
{
});
However the client is throwing the following error, i think i can understand why, i'm not sure how to fix it, or even if what i'm trying to do is possible, I've highlighted the part i think is pertinent to the question
The synchronous OperationContract method 'UpdateProcessingState' in type 'IDataService' was matched with the asynchronous OperationContract methods 'BeginUpdateProcessingState' and 'EndUpdateProcessingState' because they have the same operation name 'UpdateProcessingState'. When a synchronous OperationContract method is matched to a pair of asynchronous OperationContract methods, the two OperationContracts must have the same value for the 'Action' property. In this case, the values are different . To fix it, change the 'Action property of one of the OperationContracts to match the other. Alternatively, changing the name of one of the methods will prevent matching.
Note :
I know i can just add the stubs to the service and everything is fine, however it would be nice to be able to separate the contracts into service and client, or more specifically, the client contract inheriting from the service contract
Is this possible?
it seems if i put a namespace and a name in the Base Contract
[ServiceContract(Namespace = "http://schemas.jcurve.com/", Name = "DataService")]
public interface IDataService
{
}
and reference it in the inhertied contracts action everything seems to work
[OperationContract(AsyncPattern = true,
Action = "http://schemas.jcurve.com/DataService/UpdateProcessingState",
ReplyAction = "http://schemas.jcurve.com/DataService/UpdateProcessingStateResponse")]
IAsyncResult BeginUpdateProcessingState(ActionState state, AsyncCallback asyncCallback, object obj = null);
Note : Maybe someone has more to say on this, however i needed to add a namespace and the name in the contract , and format the url properly in the action
Ie in this case for action
http://<NameSpace>/<Name>/<Method>
and reply action
http://<NameSpace>/<Name>/<Method>Repsonse
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.