예제 #1
0
            private void Visit(OperationDescription operationDescription)
            {
                OperationContractGenerationContext context;
                bool flag = operationDescription.IsServerInitiated();
                CodeTypeDeclaration declaringType = flag ? this.context.DuplexCallbackType : this.context.ContractType;
                string           str    = (flag ? this.callbackMemberScope : this.contractMemberScope).AddUnique(operationDescription.CodeName, "Method");
                CodeMemberMethod method = new CodeMemberMethod {
                    Name = str
                };

                declaringType.Members.Add(method);
                if (this.asyncMethods)
                {
                    CodeMemberMethod method2 = new CodeMemberMethod {
                        Name = "Begin" + str
                    };
                    method2.Parameters.Add(new CodeParameterDeclarationExpression(this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(AsyncCallback)), "callback"));
                    method2.Parameters.Add(new CodeParameterDeclarationExpression(this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(object)), "asyncState"));
                    method2.ReturnType = this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult));
                    declaringType.Members.Add(method2);
                    CodeMemberMethod method3 = new CodeMemberMethod {
                        Name = "End" + str
                    };
                    method3.Parameters.Add(new CodeParameterDeclarationExpression(this.context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult)), "result"));
                    declaringType.Members.Add(method3);
                    context = new OperationContractGenerationContext(this.parent, this.context, operationDescription, declaringType, method, method2, method3);
                }
                else
                {
                    context = new OperationContractGenerationContext(this.parent, this.context, operationDescription, declaringType, method);
                }
                context.DeclaringTypeReference = operationDescription.IsServerInitiated() ? this.context.DuplexCallbackTypeReference : this.context.ContractTypeReference;
                this.context.Operations.Add(context);
                this.AddOperationContractAttributes(context);
            }
 void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
 {
     if (description == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description");
     }
     if (dispatch == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatch");
     }
     if (description.IsServerInitiated() && (this.releaseInstance != System.ServiceModel.ReleaseInstanceMode.None))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxOperationBehaviorAttributeReleaseInstanceModeDoesNotApplyToCallback", new object[] { description.Name })));
     }
     dispatch.TransactionRequired = this.autoEnlistTransaction;
     dispatch.TransactionAutoComplete = this.autoCompleteTransaction;
     dispatch.AutoDisposeParameters = this.autoDisposeParameters;
     dispatch.ReleaseInstanceBeforeCall = (this.releaseInstance & System.ServiceModel.ReleaseInstanceMode.BeforeCall) != System.ServiceModel.ReleaseInstanceMode.None;
     dispatch.ReleaseInstanceAfterCall = (this.releaseInstance & System.ServiceModel.ReleaseInstanceMode.AfterCall) != System.ServiceModel.ReleaseInstanceMode.None;
     dispatch.Impersonation = this.Impersonation;
 }
예제 #3
0
        internal static ClientRuntime BuildProxyBehavior(ServiceEndpoint serviceEndpoint, out BindingParameterCollection parameters)
        {
            parameters = new BindingParameterCollection();
            SecurityContractInformationEndpointBehavior.ClientInstance.AddBindingParameters(serviceEndpoint, parameters);

            AddBindingParameters(serviceEndpoint, parameters);

            ContractDescription contractDescription = serviceEndpoint.Contract;
            ClientRuntime       clientRuntime       = new ClientRuntime(contractDescription.Name, contractDescription.Namespace);

            clientRuntime.ContractClientType = contractDescription.ContractType;

            IdentityVerifier identityVerifier = serviceEndpoint.Binding.GetProperty <IdentityVerifier>(parameters);

            if (identityVerifier != null)
            {
                clientRuntime.IdentityVerifier = identityVerifier;
            }

            for (int i = 0; i < contractDescription.Operations.Count; i++)
            {
                OperationDescription operation = contractDescription.Operations[i];

                if (!operation.IsServerInitiated())
                {
                    DispatcherBuilder.BuildProxyOperation(operation, clientRuntime);
                }
                else
                {
                    DispatcherBuilder.BuildDispatchOperation(operation, clientRuntime.CallbackDispatchRuntime);
                }
            }

            DispatcherBuilder.ApplyClientBehavior(serviceEndpoint, clientRuntime);
            return(clientRuntime);
        }
예제 #4
0
            void Visit(OperationDescription operationDescription)
            {
                bool isCallback = operationDescription.IsServerInitiated();
                CodeTypeDeclaration       declaringType = isCallback ? context.DuplexCallbackType : context.ContractType;
                UniqueCodeIdentifierScope memberScope   = isCallback ? this.callbackMemberScope : this.contractMemberScope;

                Fx.Assert(declaringType != null, "missing callback type");

                string syncMethodName = memberScope.AddUnique(operationDescription.CodeName, Strings.DefaultOperationName);

                CodeMemberMethod syncMethod = new CodeMemberMethod();

                syncMethod.Name = syncMethodName;
                declaringType.Members.Add(syncMethod);

                OperationContractGenerationContext operationContext;
                CodeMemberMethod beginMethod = null;
                CodeMemberMethod endMethod   = null;

                if (asyncMethods)
                {
                    beginMethod      = new CodeMemberMethod();
                    beginMethod.Name = ServiceReflector.BeginMethodNamePrefix + syncMethodName;
                    beginMethod.Parameters.Add(new CodeParameterDeclarationExpression(context.ServiceContractGenerator.GetCodeTypeReference(typeof(AsyncCallback)), Strings.AsyncCallbackArgName));
                    beginMethod.Parameters.Add(new CodeParameterDeclarationExpression(context.ServiceContractGenerator.GetCodeTypeReference(typeof(object)), Strings.AsyncStateArgName));
                    beginMethod.ReturnType = context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult));
                    declaringType.Members.Add(beginMethod);

                    endMethod      = new CodeMemberMethod();
                    endMethod.Name = ServiceReflector.EndMethodNamePrefix + syncMethodName;
                    endMethod.Parameters.Add(new CodeParameterDeclarationExpression(context.ServiceContractGenerator.GetCodeTypeReference(typeof(IAsyncResult)), Strings.AsyncResultArgName));
                    declaringType.Members.Add(endMethod);

                    operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, beginMethod, endMethod);
                }
                else
                {
                    operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod);
                }

                if (taskMethod)
                {
                    if (isCallback)
                    {
                        if (beginMethod == null)
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod);
                        }
                        else
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, beginMethod, endMethod);
                        }
                    }
                    else
                    {
                        CodeMemberMethod taskBasedAsyncMethod = new CodeMemberMethod {
                            Name = syncMethodName + ServiceReflector.AsyncMethodNameSuffix
                        };
                        declaringType.Members.Add(taskBasedAsyncMethod);
                        if (beginMethod == null)
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, taskBasedAsyncMethod);
                        }
                        else
                        {
                            operationContext = new OperationContractGenerationContext(parent, context, operationDescription, declaringType, syncMethod, beginMethod, endMethod, taskBasedAsyncMethod);
                        }
                    }
                }

                operationContext.DeclaringTypeReference = operationDescription.IsServerInitiated() ? context.DuplexCallbackTypeReference : context.ContractTypeReference;

                context.Operations.Add(operationContext);

                AddOperationContractAttributes(operationContext);
            }