private static OperationDescription CreateSubmitOperationDescription(ContractDescription declaringContract, DomainServiceDescription domainServiceDescription) { OperationDescription operationDesc = ServiceUtility.CreateBasicOperationDescription(declaringContract, ServiceUtility.SubmitOperationName); // Propagate behaviors. MethodInfo submitMethod = declaringContract.ContractType.GetMethod("Submit"); foreach (IOperationBehavior behavior in submitMethod.GetCustomAttributes(/* inherit */ true).OfType <IOperationBehavior>()) { operationDesc.Behaviors.Add(behavior); } string action = ServiceUtility.GetMessageAction(declaringContract, operationDesc.Name, /* action */ null); string responseAction = ServiceUtility.GetResponseMessageAction(declaringContract, operationDesc.Name, /* action */ null); // Define operation input (IEnumerable<ChangeSetEntry> changeSet). MessageDescription inputMessageDesc = new MessageDescription(action, MessageDirection.Input); inputMessageDesc.Body.WrapperName = operationDesc.Name; inputMessageDesc.Body.WrapperNamespace = ServiceUtility.DefaultNamespace; MessagePartDescription changeSetParameterPartDesc = new MessagePartDescription("changeSet", ServiceUtility.DefaultNamespace) { Type = typeof(IEnumerable <ChangeSetEntry>) }; inputMessageDesc.Body.Parts.Add(changeSetParameterPartDesc); operationDesc.Messages.Add(inputMessageDesc); // Define operation output (IEnumerable<ChangeSetEntry>). MessageDescription outputMessageDesc = new MessageDescription(responseAction, MessageDirection.Output); outputMessageDesc.Body.WrapperName = operationDesc.Name + "Response"; outputMessageDesc.Body.WrapperNamespace = ServiceUtility.DefaultNamespace; outputMessageDesc.Body.ReturnValue = new MessagePartDescription(operationDesc.Name + "Result", ServiceUtility.DefaultNamespace) { Type = typeof(IEnumerable <ChangeSetEntry>) }; operationDesc.Messages.Add(outputMessageDesc); // Register types used in custom methods. Custom methods show up as part of the changeset. // KnownTypes are required for all non-primitive and non-string since these types will show up in the change set. foreach (DomainOperationEntry customOp in domainServiceDescription.DomainOperationEntries.Where(op => op.Operation == DomainOperation.Custom)) { // KnownTypes will be added during surrogate registration for all entity and // complex types. We skip the first parameter because it is an entity type. We also // skip all complex types. Note, we do not skip complex type collections because // the act of registering surrogates only adds the type, and KnownTypes needs to // know about any collections. foreach (Type parameterType in customOp.Parameters.Skip(1).Select(p => p.ParameterType).Where( t => !t.IsPrimitive && t != typeof(string) && !domainServiceDescription.ComplexTypes.Contains(t))) { operationDesc.KnownTypes.Add(parameterType); } } return(operationDesc); }
public static string GetFaultMessageAction(ContractDescription contractName, string opname, string action) { return(ServiceUtility.GetMessageAction(contractName, opname, action, /* isResponse */ false) + typeof(DomainServiceFault).Name); }
public static string GetResponseMessageAction(ContractDescription contractName, string opname, string action) { return(ServiceUtility.GetMessageAction(contractName, opname, action, /* isResponse */ true)); }
private static OperationDescription CreateOperationDescription(ContractDescription declaringContract, DomainOperationEntry operation) { OperationDescription operationDesc = ServiceUtility.CreateBasicOperationDescription(declaringContract, operation.Name); // Propagate behaviors. foreach (IOperationBehavior behavior in operation.Attributes.OfType <IOperationBehavior>()) { operationDesc.Behaviors.Add(behavior); } // Add standard behaviors. if ((operation.Operation == DomainOperation.Query && ((QueryAttribute)operation.OperationAttribute).HasSideEffects) || (operation.Operation == DomainOperation.Invoke && ((InvokeAttribute)operation.OperationAttribute).HasSideEffects)) { // REVIEW: We should actually be able to remove the following line entirely, since // all operations are [WebInvoke] by default. ServiceUtility.EnsureBehavior <WebInvokeAttribute>(operationDesc); } else if (operation.Operation == DomainOperation.Query && !((QueryAttribute)operation.OperationAttribute).HasSideEffects) { // This is a query with HasSideEffects == false, allow both POST and GET var invoke = ServiceUtility.EnsureBehavior <WebInvokeAttribute>(operationDesc); invoke.Method = "*"; // We need to set URI template in order to allow the normal parameters to be extracted from the Uri if (operation.Parameters.Count > 0) { invoke.UriTemplate = GetDefaultQueryUriTemplate(operation); } } else { ServiceUtility.EnsureBehavior <WebGetAttribute>(operationDesc); } string action = ServiceUtility.GetMessageAction(declaringContract, operationDesc.Name, /* action */ null); // Define operation input. MessageDescription inputMessageDesc = new MessageDescription(action, MessageDirection.Input); inputMessageDesc.Body.WrapperName = operationDesc.Name; inputMessageDesc.Body.WrapperNamespace = ServiceUtility.DefaultNamespace; for (int i = 0; i < operation.Parameters.Count; i++) { DomainOperationParameter parameter = operation.Parameters[i]; MessagePartDescription parameterPartDesc = new MessagePartDescription(parameter.Name, ServiceUtility.DefaultNamespace) { Index = i, Type = SerializationUtility.GetClientType(parameter.ParameterType) }; inputMessageDesc.Body.Parts.Add(parameterPartDesc); } operationDesc.Messages.Add(inputMessageDesc); // Define operation output. string responseAction = ServiceUtility.GetResponseMessageAction(declaringContract, operationDesc.Name, /* action */ null); MessageDescription outputMessageDesc = new MessageDescription(responseAction, MessageDirection.Output); outputMessageDesc.Body.WrapperName = operationDesc.Name + "Response"; outputMessageDesc.Body.WrapperNamespace = ServiceUtility.DefaultNamespace; if (operation.ReturnType != typeof(void)) { outputMessageDesc.Body.ReturnValue = new MessagePartDescription(operationDesc.Name + "Result", ServiceUtility.DefaultNamespace) { Type = SerializationUtility.GetClientType(operation.ReturnType) }; } operationDesc.Messages.Add(outputMessageDesc); return(operationDesc); }