예제 #1
0
        private MessageDescription CreateParameterMessageDescription(ContractDescription contract, ParameterInfo[] parameters, Type returnType, ICustomAttributeProvider returnCustomAttributes, System.ServiceModel.Description.XmlName returnValueName, string methodName, string ns, string action, MessageDirection direction, bool allowReferences)
        {
            MessageDescription description = new MessageDescription(action, direction)
            {
                Body = { WrapperNamespace = ns }
            };

            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo parameterInfo = parameters[i];
                Type          parameterType = TypeLoader.GetParameterType(parameterInfo);
                if (!ComPlusTypeValidator.IsValidParameter(parameterType, parameterInfo, allowReferences))
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("InvalidWebServiceParameter", new object[] { parameterInfo.Name, parameterType.Name, methodName, contract.Name })));
                }
                MessagePartDescription item = this.CreateMessagePartDescription(parameterType, new System.ServiceModel.Description.XmlName(parameterInfo.Name), ns, i);
                description.Body.Parts.Add(item);
            }
            System.ServiceModel.Description.XmlName operationName = new System.ServiceModel.Description.XmlName(methodName);
            if (returnType == null)
            {
                description.Body.WrapperName = operationName.EncodedName;
                return(description);
            }
            description.Body.WrapperName = TypeLoader.GetBodyWrapperResponseName(operationName).EncodedName;
            if (!ComPlusTypeValidator.IsValidParameter(returnType, returnCustomAttributes, allowReferences))
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("InvalidWebServiceReturnValue", new object[] { returnType.Name, methodName, contract.Name })));
            }
            MessagePartDescription description3 = this.CreateMessagePartDescription(returnType, returnValueName, ns, 0);

            description.Body.ReturnValue = description3;
            return(description);
        }
예제 #2
0
                internal void EnsureMessageInfos()
                {
                    if (_request == null)
                    {
                        foreach (Type knownType in Operation.KnownTypes)
                        {
                            if (knownType == null)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxKnownTypeNull, Operation.Name)));
                            }
                            _parent._importer.IncludeType(knownType);
                        }
                        _request = CreateMessageInfo(this.Operation.Messages[0], ":Request");
                        // We don't do the following check at Net Native runtime because XmlMapping.XsdElementName
                        // is not available at that time.
                        bool skipVerifyXsdElementName = false;
#if FEATURE_NETNATIVE
                        skipVerifyXsdElementName = GeneratedXmlSerializers.IsInitialized;
#endif
                        if (_request != null && this.IsRpc && this.Operation.IsValidateRpcWrapperName && !skipVerifyXsdElementName && _request.BodyMapping.XsdElementName != this.Operation.Name)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxRpcMessageBodyPartNameInvalid, Operation.Name, this.Operation.Messages[0].MessageName, _request.BodyMapping.XsdElementName, this.Operation.Name)));
                        }
                        if (!this.IsOneWay)
                        {
                            _reply = CreateMessageInfo(this.Operation.Messages[1], ":Response");
                            XmlName responseName = TypeLoader.GetBodyWrapperResponseName(this.Operation.Name);
                            if (_reply != null && this.IsRpc && this.Operation.IsValidateRpcWrapperName && !skipVerifyXsdElementName && _reply.BodyMapping.XsdElementName != responseName.EncodedName)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxRpcMessageBodyPartNameInvalid, Operation.Name, this.Operation.Messages[1].MessageName, _reply.BodyMapping.XsdElementName, responseName.EncodedName)));
                            }
                        }
                        if (this.Attribute.SupportFaults)
                        {
                            GenerateXmlSerializerFaultContractInfos();
                        }
                    }
                }
 internal void EnsureMessageInfos()
 {
     if (this.request == null)
     {
         foreach (System.Type type in this.Operation.KnownTypes)
         {
             if (type == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxKnownTypeNull", new object[] { this.Operation.Name })));
             }
             this.parent.importer.IncludeType(type, this.IsEncoded);
         }
         this.request = this.CreateMessageInfo(this.Operation.Messages[0], ":Request");
         if (((this.request != null) && this.IsRpc) && (this.Operation.IsValidateRpcWrapperName && (this.request.BodyMapping.XsdElementName != this.Operation.Name)))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxRpcMessageBodyPartNameInvalid", new object[] { this.Operation.Name, this.Operation.Messages[0].MessageName, this.request.BodyMapping.XsdElementName, this.Operation.Name })));
         }
         if (!this.IsOneWay)
         {
             this.reply = this.CreateMessageInfo(this.Operation.Messages[1], ":Response");
             System.ServiceModel.Description.XmlName bodyWrapperResponseName = TypeLoader.GetBodyWrapperResponseName(this.Operation.Name);
             if (((this.reply != null) && this.IsRpc) && (this.Operation.IsValidateRpcWrapperName && (this.reply.BodyMapping.XsdElementName != bodyWrapperResponseName.EncodedName)))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxRpcMessageBodyPartNameInvalid", new object[] { this.Operation.Name, this.Operation.Messages[1].MessageName, this.reply.BodyMapping.XsdElementName, bodyWrapperResponseName.EncodedName })));
             }
         }
         if (this.Attribute.SupportFaults)
         {
             this.GenerateXmlSerializerFaultContractInfos();
         }
     }
 }
예제 #4
0
        MessageDescription CreateParameterMessageDescription(ContractDescription contract,
                                                             ParameterInfo[] parameters,
                                                             Type returnType,
                                                             ICustomAttributeProvider returnCustomAttributes,
                                                             XmlName returnValueName,
                                                             string methodName,
                                                             string ns,
                                                             string action,
                                                             MessageDirection direction,
                                                             bool allowReferences)
        {
            MessageDescription messageDescription = new MessageDescription(action, direction);

            messageDescription.Body.WrapperNamespace = ns;

            for (int index = 0; index < parameters.Length; index++)
            {
                ParameterInfo parameter     = parameters[index];
                Type          parameterType = TypeLoader.GetParameterType(parameter);

                if (!ComPlusTypeValidator.IsValidParameter(parameterType, parameter, allowReferences))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.InvalidWebServiceParameter,
                                                                                                                    parameter.Name,
                                                                                                                    parameterType.Name,
                                                                                                                    methodName,
                                                                                                                    contract.Name)));
                }

                MessagePartDescription messagePart = CreateMessagePartDescription(parameterType,
                                                                                  new XmlName(parameter.Name),
                                                                                  ns,
                                                                                  index);
                messageDescription.Body.Parts.Add(messagePart);
            }

            XmlName xmlName = new XmlName(methodName);

            if (returnType == null)
            {
                messageDescription.Body.WrapperName = xmlName.EncodedName;
            }
            else
            {
                messageDescription.Body.WrapperName = TypeLoader.GetBodyWrapperResponseName(xmlName).EncodedName;

                if (!ComPlusTypeValidator.IsValidParameter(returnType, returnCustomAttributes, allowReferences))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(SR.GetString(SR.InvalidWebServiceReturnValue,
                                                                                                                    returnType.Name,
                                                                                                                    methodName,
                                                                                                                    contract.Name)));
                }

                MessagePartDescription messagePart = CreateMessagePartDescription(returnType,
                                                                                  returnValueName,
                                                                                  ns,
                                                                                  0);
                messageDescription.Body.ReturnValue = messagePart;
            }

            return(messageDescription);
        }