Esempio n. 1
0
        private OperationDescription CreateOperationDescription(ContractDescription contract, System.Reflection.MethodInfo methodInfo, ComContractElement config, bool allowReferences)
        {
            System.ServiceModel.Description.XmlName methodName      = new System.ServiceModel.Description.XmlName(ServiceReflector.GetLogicalName(methodInfo));
            System.ServiceModel.Description.XmlName returnValueName = TypeLoader.GetReturnValueName(methodName);
            if (ServiceReflector.IsBegin(methodInfo))
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NoAsyncOperationsAllowed());
            }
            if (contract.Operations.FindAll(methodName.EncodedName).Count != 0)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DuplicateOperation());
            }
            OperationDescription description = new OperationDescription(methodName.EncodedName, contract)
            {
                SyncMethod    = methodInfo,
                IsInitiating  = true,
                IsTerminating = false
            };

            description.KnownTypes.Add(typeof(Array));
            description.KnownTypes.Add(typeof(DBNull));
            description.KnownTypes.Add(typeof(CurrencyWrapper));
            description.KnownTypes.Add(typeof(ErrorWrapper));
            if (allowReferences)
            {
                description.KnownTypes.Add(typeof(PersistStreamTypeWrapper));
            }
            foreach (ComUdtElement element in config.UserDefinedTypes)
            {
                Type type;
                Guid typeLibId = Fx.CreateGuid(element.TypeLibID);
                TypeCacheManager.Provider.FindOrCreateType(typeLibId, element.TypeLibVersion, Fx.CreateGuid(element.TypeDefID), out type, false);
                this.info.AddUdt(type, typeLibId);
                description.KnownTypes.Add(type);
            }
            string             ns           = contract.Namespace;
            XmlQualifiedName   contractName = new XmlQualifiedName(contract.Name, ns);
            string             action       = NamingHelper.GetMessageAction(contractName, methodName.DecodedName, null, false);
            string             str3         = NamingHelper.GetMessageAction(contractName, methodName.DecodedName, null, true);
            MessageDescription item         = this.CreateIncomingMessageDescription(contract, methodInfo, ns, action, allowReferences);
            MessageDescription description3 = this.CreateOutgoingMessageDescription(contract, methodInfo, returnValueName, ns, str3, allowReferences);

            description.Messages.Add(item);
            description.Messages.Add(description3);
            return(description);
        }
Esempio n. 2
0
        //
        // Note - the code below this line a paraphrase of the SM reflection code in TypeLoader.cs
        // Ideally we would be re-using their code, but our assumptions are too disjoint
        // for that to be realistic at the time of writing (12/2004).
        //

        OperationDescription CreateOperationDescription(ContractDescription contract, MethodInfo methodInfo, ComContractElement config, bool allowReferences)
        {
            XmlName operationName   = new XmlName(ServiceReflector.GetLogicalName(methodInfo));
            XmlName returnValueName = TypeLoader.GetReturnValueName(operationName);

            if (ServiceReflector.IsBegin(methodInfo) || ServiceReflector.IsTask(methodInfo))
            {
                Fx.Assert("No async operations allowed");

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NoAsyncOperationsAllowed());
            }
            if (contract.Operations.FindAll(operationName.EncodedName).Count != 0)
            {
                Fx.Assert("Duplicate operation name");

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DuplicateOperation());
            }

            OperationDescription operationDescription = new OperationDescription(operationName.EncodedName, contract);

            operationDescription.SyncMethod    = methodInfo;
            operationDescription.IsInitiating  = true;
            operationDescription.IsTerminating = false;

            operationDescription.KnownTypes.Add(typeof(Array));
            operationDescription.KnownTypes.Add(typeof(DBNull));
            operationDescription.KnownTypes.Add(typeof(CurrencyWrapper));
            operationDescription.KnownTypes.Add(typeof(ErrorWrapper));

            if (allowReferences)
            {
                operationDescription.KnownTypes.Add(typeof(PersistStreamTypeWrapper));
            }

            foreach (ComUdtElement udt in config.UserDefinedTypes)
            {
                Type knownType;

                Guid typeLibID = Fx.CreateGuid(udt.TypeLibID);

                TypeCacheManager.Provider.FindOrCreateType(typeLibID, udt.TypeLibVersion, Fx.CreateGuid(udt.TypeDefID), out knownType, false);

                this.info.AddUdt(knownType, typeLibID);
                operationDescription.KnownTypes.Add(knownType);
            }


            string           ns            = contract.Namespace;
            XmlQualifiedName contractQName = new XmlQualifiedName(contract.Name, ns);

            string requestAction = NamingHelper.GetMessageAction(contractQName,
                                                                 operationName.DecodedName,
                                                                 null,
                                                                 false);

            string responseAction = NamingHelper.GetMessageAction(contractQName,
                                                                  operationName.DecodedName,
                                                                  null,
                                                                  true);

            MessageDescription inMessage = CreateIncomingMessageDescription(contract,
                                                                            methodInfo,
                                                                            ns,
                                                                            requestAction,
                                                                            allowReferences);

            MessageDescription outMessage = CreateOutgoingMessageDescription(contract,
                                                                             methodInfo,
                                                                             returnValueName,
                                                                             ns,
                                                                             responseAction,
                                                                             allowReferences);

            operationDescription.Messages.Add(inMessage);
            operationDescription.Messages.Add(outMessage);

            return(operationDescription);
        }