static void FillOperationsForInterface (ContractDescription cd, Type exactContractType, Type givenServiceType, bool isCallback)
{
// FIXME: load Behaviors
MethodInfo [] contractMethods = exactContractType.IsInterface ? GetAllMethods (exactContractType) : exactContractType.GetMethods ();
MethodInfo [] serviceMethods = contractMethods;
if (givenServiceType != null && exactContractType.IsInterface) {
var l = new List<MethodInfo> ();
foreach (Type t in GetAllInterfaceTypes (exactContractType))
l.AddRange (givenServiceType.GetInterfaceMap (t).TargetMethods);
serviceMethods = l.ToArray ();
}
for (int i = 0; i < contractMethods.Length; ++i)
{
MethodInfo mi = contractMethods [i];
OperationContractAttribute oca = GetOperationContractAttribute (mi);
if (oca == null)
continue;
MethodInfo end = null;
if (oca.AsyncPattern) {
if (String.Compare ("Begin", 0, mi.Name,0, 5) != 0)
throw new InvalidOperationException ("For async operation contract patterns, the initiator method name must start with 'Begin'.");
string endName = "End" + mi.Name.Substring (5);
end = mi.DeclaringType.GetMethod (endName);
if (end == null)
throw new InvalidOperationException (String.Format ("'{0}' method is missing. For async operation contract patterns, corresponding End method is required for each Begin method.", endName));
if (GetOperationContractAttribute (end) != null)
throw new InvalidOperationException ("Async 'End' method must not have OperationContractAttribute. It is automatically treated as the EndMethod of the corresponding 'Begin' method.");
}
OperationDescription od = GetOrCreateOperation (cd, mi, serviceMethods [i], oca, end != null ? end.ReturnType : null, isCallback);
if (end != null)
od.EndMethod = end;
}
}