Beispiel #1
0
 public static string GetResponseMessageAction(ContractDescription contractName, string opname, string action)
 {
     return(ServiceUtility.GetMessageAction(contractName, opname, action, /* isResponse */ true));
 }
Beispiel #2
0
 public static string GetFaultMessageAction(ContractDescription contractName, string opname, string action)
 {
     return(ServiceUtility.GetMessageAction(contractName, opname, action, /* isResponse */ false) + typeof(DomainServiceFault).Name);
 }
Beispiel #3
0
        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);
        }