コード例 #1
0
        private ContractDescription CreateContractDescriptionInternal(Guid iid, Type type)
        {
            ComContractElement comContract = ConfigLoader.LookupComContract(iid);

            if (comContract == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("InterfaceNotFoundInConfig", new object[] { iid })));
            }
            if (string.IsNullOrEmpty(comContract.Name) || string.IsNullOrEmpty(comContract.Namespace))
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("CannotHaveNullOrEmptyNameOrNamespaceForIID", new object[] { iid })));
            }
            ContractDescription contract = new ContractDescription(comContract.Name, comContract.Namespace)
            {
                ContractType = type,
                SessionMode  = comContract.RequiresSession ? SessionMode.Required : SessionMode.Allowed
            };
            bool        flag = false;
            List <Guid> list = new List <Guid>();

            foreach (ComPersistableTypeElement element2 in comContract.PersistableTypes)
            {
                Guid item = Fx.CreateGuid(element2.ID);
                list.Add(item);
            }
            IDataContractSurrogate contractSurrogate = null;

            if ((list.Count > 0) || comContract.PersistableTypes.EmitClear)
            {
                contractSurrogate = new DataContractSurrogateForPersistWrapper(list.ToArray());
            }
            foreach (ComMethodElement element3 in comContract.ExposedMethods)
            {
                flag = false;
                foreach (System.Reflection.MethodInfo info in type.GetMethods())
                {
                    if (info.Name == element3.ExposedMethod)
                    {
                        OperationDescription operation = this.CreateOperationDescription(contract, info, comContract, null != contractSurrogate);
                        this.ConfigureOperationDescriptionBehaviors(operation, contractSurrogate);
                        contract.Operations.Add(operation);
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("MethodGivenInConfigNotFoundOnInterface", new object[] { element3.ExposedMethod, iid })));
                }
            }
            if (contract.Operations.Count == 0)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("NoneOfTheMethodsForInterfaceFoundInConfig", new object[] { iid })));
            }
            this.ConfigureContractDescriptionBehaviors(contract);
            return(contract);
        }
 private ContractDescription CreateContractDescriptionInternal(Guid iid, Type type)
 {
     ComContractElement comContract = ConfigLoader.LookupComContract(iid);
     if (comContract == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("InterfaceNotFoundInConfig", new object[] { iid })));
     }
     if (string.IsNullOrEmpty(comContract.Name) || string.IsNullOrEmpty(comContract.Namespace))
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("CannotHaveNullOrEmptyNameOrNamespaceForIID", new object[] { iid })));
     }
     ContractDescription contract = new ContractDescription(comContract.Name, comContract.Namespace) {
         ContractType = type,
         SessionMode = comContract.RequiresSession ? SessionMode.Required : SessionMode.Allowed
     };
     bool flag = false;
     List<Guid> list = new List<Guid>();
     foreach (ComPersistableTypeElement element2 in comContract.PersistableTypes)
     {
         Guid item = Fx.CreateGuid(element2.ID);
         list.Add(item);
     }
     IDataContractSurrogate contractSurrogate = null;
     if ((list.Count > 0) || comContract.PersistableTypes.EmitClear)
     {
         contractSurrogate = new DataContractSurrogateForPersistWrapper(list.ToArray());
     }
     foreach (ComMethodElement element3 in comContract.ExposedMethods)
     {
         flag = false;
         foreach (System.Reflection.MethodInfo info in type.GetMethods())
         {
             if (info.Name == element3.ExposedMethod)
             {
                 OperationDescription operation = this.CreateOperationDescription(contract, info, comContract, null != contractSurrogate);
                 this.ConfigureOperationDescriptionBehaviors(operation, contractSurrogate);
                 contract.Operations.Add(operation);
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("MethodGivenInConfigNotFoundOnInterface", new object[] { element3.ExposedMethod, iid })));
         }
     }
     if (contract.Operations.Count == 0)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("NoneOfTheMethodsForInterfaceFoundInConfig", new object[] { iid })));
     }
     this.ConfigureContractDescriptionBehaviors(contract);
     return contract;
 }
コード例 #3
0
        ContractDescription CreateContractDescriptionInternal(Guid iid, Type type)
        {
            ComContractElement contractConfigElement = ConfigLoader.LookupComContract(iid);

            if (contractConfigElement == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.InterfaceNotFoundInConfig, iid)));
            if (String.IsNullOrEmpty(contractConfigElement.Name) || String.IsNullOrEmpty(contractConfigElement.Namespace))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.CannotHaveNullOrEmptyNameOrNamespaceForIID, iid)));

            ContractDescription contract = new ContractDescription(contractConfigElement.Name, contractConfigElement.Namespace);
            contract.ContractType = type;
            contract.SessionMode = contractConfigElement.RequiresSession ? SessionMode.Required : SessionMode.Allowed;

            bool methodFound = false;

            List<Guid> guidList = new List<Guid>();

            foreach (ComPersistableTypeElement typeElement in contractConfigElement.PersistableTypes)
            {
                Guid typeGuid = Fx.CreateGuid(typeElement.ID);

                guidList.Add(typeGuid);
            }

            IDataContractSurrogate contractSurrogate = null;

            // We create a surrogate when the persistable types config section is there
            // even if we have no types that we allow.
            // That way we have control over the error when the client tries to make a call 
            // persistable type.
            if (guidList.Count > 0 || contractConfigElement.PersistableTypes.EmitClear)
            {
                contractSurrogate = new DataContractSurrogateForPersistWrapper(guidList.ToArray());
            }

            foreach (ComMethodElement configMethod in contractConfigElement.ExposedMethods)
            {
                methodFound = false;
                foreach (MethodInfo method in type.GetMethods())
                {
                    if (method.Name == configMethod.ExposedMethod)
                    {
                        OperationDescription operation = CreateOperationDescription(contract, method, contractConfigElement, (null != contractSurrogate));
                        ConfigureOperationDescriptionBehaviors(operation, contractSurrogate);
                        contract.Operations.Add(operation);
                        methodFound = true;
                        break;
                    }
                }
                if (!methodFound)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.MethodGivenInConfigNotFoundOnInterface, configMethod.ExposedMethod, iid)));
            }

            if (contract.Operations.Count == 0)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.NoneOfTheMethodsForInterfaceFoundInConfig, iid)));

            ConfigureContractDescriptionBehaviors(contract);
            return contract;
        }
コード例 #4
0
        ContractDescription CreateContractDescriptionInternal(Guid iid, Type type)
        {
            ComContractElement contractConfigElement = ConfigLoader.LookupComContract(iid);

            if (contractConfigElement == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.InterfaceNotFoundInConfig, iid)));
            }
            if (String.IsNullOrEmpty(contractConfigElement.Name) || String.IsNullOrEmpty(contractConfigElement.Namespace))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.CannotHaveNullOrEmptyNameOrNamespaceForIID, iid)));
            }

            ContractDescription contract = new ContractDescription(contractConfigElement.Name, contractConfigElement.Namespace);

            contract.ContractType = type;
            contract.SessionMode  = contractConfigElement.RequiresSession ? SessionMode.Required : SessionMode.Allowed;

            bool methodFound = false;

            List <Guid> guidList = new List <Guid>();

            foreach (ComPersistableTypeElement typeElement in contractConfigElement.PersistableTypes)
            {
                Guid typeGuid = Fx.CreateGuid(typeElement.ID);

                guidList.Add(typeGuid);
            }

            IDataContractSurrogate contractSurrogate = null;

            // We create a surrogate when the persistable types config section is there
            // even if we have no types that we allow.
            // That way we have control over the error when the client tries to make a call
            // persistable type.
            if (guidList.Count > 0 || contractConfigElement.PersistableTypes.EmitClear)
            {
                contractSurrogate = new DataContractSurrogateForPersistWrapper(guidList.ToArray());
            }

            foreach (ComMethodElement configMethod in contractConfigElement.ExposedMethods)
            {
                methodFound = false;
                foreach (MethodInfo method in type.GetMethods())
                {
                    if (method.Name == configMethod.ExposedMethod)
                    {
                        OperationDescription operation = CreateOperationDescription(contract, method, contractConfigElement, (null != contractSurrogate));
                        ConfigureOperationDescriptionBehaviors(operation, contractSurrogate);
                        contract.Operations.Add(operation);
                        methodFound = true;
                        break;
                    }
                }
                if (!methodFound)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.MethodGivenInConfigNotFoundOnInterface, configMethod.ExposedMethod, iid)));
                }
            }

            if (contract.Operations.Count == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.NoneOfTheMethodsForInterfaceFoundInConfig, iid)));
            }

            ConfigureContractDescriptionBehaviors(contract);
            return(contract);
        }