コード例 #1
0
        /// <summary>
        /// Add the Ping method to the existing contract
        /// </summary>
        private void AddPingToContractDescription(ContractDescription contractDescription)
        {
            OperationDescription pingOperationDescription = new OperationDescription(PingOperationName, contractDescription);

            MessageDescription inputMessageDescription = new MessageDescription(
                GetAction(contractDescription, PingOperationName),
                MessageDirection.Input);

            MessageDescription outputMessageDescription = new MessageDescription(
                GetAction(contractDescription, PingResponse),
                MessageDirection.Output);

            MessagePartDescription returnValue = new MessagePartDescription("PingResult", contractDescription.Namespace);

            returnValue.Type = typeof(DateTime);
            outputMessageDescription.Body.ReturnValue = returnValue;

            inputMessageDescription.Body.WrapperName = PingOperationName;
            inputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace;
            outputMessageDescription.Body.WrapperName = PingResponse;
            outputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace;

            pingOperationDescription.Messages.Add(inputMessageDescription);
            pingOperationDescription.Messages.Add(outputMessageDescription);

            pingOperationDescription.Behaviors.Add(new DataContractSerializerOperationBehavior(pingOperationDescription));
            pingOperationDescription.Behaviors.Add(new PingOperationBehavior());

            contractDescription.Operations.Add(pingOperationDescription);
        }
コード例 #2
0
 private void ValidateMessagePartDescription(MessagePartDescription part)
 {
     if (part != null)
     {
         this.ValidateCustomSerializableType(part.Type);
     }
 }
コード例 #3
0
 internal void Add(MessagePartDescription part, XmlMemberMapping memberMapping, XmlMembersMapping membersMapping, bool isEncoded)
 {
     PartInfo partInfo = new PartInfo();
     partInfo.MemberMapping = memberMapping;
     partInfo.MembersMapping = membersMapping;
     partInfo.IsEncoded = isEncoded;
     partInfoTable[part] = partInfo;
 }
コード例 #4
0
ファイル: XmlMessagesFormatter.cs プロジェクト: nickchal/pash
		private XmlReflectionMember CreateReflectionMember (MessagePartDescription partDesc, bool isReturnValue)
		{
			XmlReflectionMember m = new XmlReflectionMember ();
			m.IsReturnValue = isReturnValue;
			m.MemberName = partDesc.Name;
			m.MemberType = partDesc.Type;
			return m;
		}
コード例 #5
0
ファイル: XmlMessagesFormatter.cs プロジェクト: nlhepler/mono
		private XmlReflectionMember CreateReflectionMember (MessagePartDescription partDesc, bool isReturnValue)
		{
			XmlReflectionMember m = new XmlReflectionMember ();
			m.IsReturnValue = isReturnValue;
			m.MemberName = partDesc.Name;
			m.MemberType = partDesc.Type;
			m.XmlAttributes = partDesc.MemberInfo == null ? new XmlAttributes () : new XmlAttributes (partDesc.MemberInfo);
			return m;
		}
コード例 #6
0
 public RequestMessagePartDescription(MessagePartDescription messagePart, MessagePartType partType, string alias)
     : base(messagePart.Name, messagePart.Namespace)
 {
     Index = messagePart.Index;
     MemberInfo = messagePart.MemberInfo;
     Multiple = messagePart.Multiple;
     ProtectionLevel = messagePart.ProtectionLevel;
     Type = messagePart.Type;
     Alias = alias;
     PartType = partType;
 }
 internal static XmlReflectionMember GetXmlReflectionMember(MessagePartDescription part, bool isRpc, bool isEncoded, bool isWrapped)
 {
     string ns = isRpc ? null : part.Namespace;
     ICustomAttributeProvider additionalAttributesProvider = null;
     if (isEncoded || (part.AdditionalAttributesProvider is MemberInfo))
     {
         additionalAttributesProvider = part.AdditionalAttributesProvider;
     }
     System.ServiceModel.Description.XmlName memberName = string.IsNullOrEmpty(part.UniquePartName) ? null : new System.ServiceModel.Description.XmlName(part.UniquePartName, true);
     System.ServiceModel.Description.XmlName xmlName = part.XmlName;
     return GetXmlReflectionMember(memberName, xmlName, ns, part.Type, additionalAttributesProvider, part.Multiple, isEncoded, isWrapped);
 }
コード例 #8
0
ファイル: StreamFormatter.cs プロジェクト: dmetzgar/wcf
 private StreamFormatter(MessageDescription messageDescription, MessagePartDescription streamPart, string operationName, bool isRequest)
 {
     if ((object)streamPart == (object)messageDescription.Body.ReturnValue)
         _streamIndex = returnValueIndex;
     else
         _streamIndex = streamPart.Index;
     _wrapperName = messageDescription.Body.WrapperName;
     _wrapperNS = messageDescription.Body.WrapperNamespace;
     _partName = streamPart.Name;
     _partNS = streamPart.Namespace;
     _isRequest = isRequest;
     _operationName = operationName;
 }
コード例 #9
0
 internal MessagePartDescription(MessagePartDescription other)
 {
     this.name = other.name;
     this.ns = other.ns;
     this.index = other.index;
     this.type = other.type;
     this.serializationPosition = other.serializationPosition;
     this.hasProtectionLevel = other.hasProtectionLevel;
     this.protectionLevel = other.protectionLevel;
     this.memberInfo = other.memberInfo;
     this.multiple = other.multiple;
     this.additionalAttributesProvider = other.additionalAttributesProvider;
     this.baseType = other.baseType;
     this.uniquePartName = other.uniquePartName;
 }
コード例 #10
0
 internal MessagePartDescription(MessagePartDescription other)
 {
     _name = other._name;
     _ns = other._ns;
     _index = other._index;
     _type = other._type;
     _serializationPosition = other._serializationPosition;
     _hasProtectionLevel = other._hasProtectionLevel;
     _protectionLevel = other._protectionLevel;
     _memberInfo = other._memberInfo;
     _multiple = other._multiple;
     _additionalAttributesProvider = other._additionalAttributesProvider;
     _baseType = other._baseType;
     _uniquePartName = other._uniquePartName;
 }
コード例 #11
0
 public static void AddMessagePartDescription(OperationDescription operation, bool isResponse, MessageDescription message, string[] argumentNames, Type[] argumentTypes)
 {
     string ns = operation.DeclaringContract.Namespace;
     for (int i = 0; i < argumentNames.Length; i++)
     {
         string name = argumentNames[i];
         MessagePartDescription item = new MessagePartDescription(NamingHelper.XmlName(name), ns) {
             Index = i,
             Type = argumentTypes[i]
         };
         message.Body.Parts.Add(item);
     }
     if (isResponse)
     {
         SetReturnValue(message, operation);
     }
 }
コード例 #12
0
 private StreamFormatter(MessageDescription messageDescription, MessagePartDescription streamPart, string operationName, bool isRequest)
 {
     if (streamPart == messageDescription.Body.ReturnValue)
     {
         this.streamIndex = -1;
     }
     else
     {
         this.streamIndex = streamPart.Index;
     }
     this.wrapperName = messageDescription.Body.WrapperName;
     this.wrapperNS = messageDescription.Body.WrapperNamespace;
     this.partName = streamPart.Name;
     this.partNS = streamPart.Namespace;
     this.isRequest = isRequest;
     this.operationName = operationName;
 }
コード例 #13
0
 public static void AddMessagePartDescription(OperationDescription operation, bool isResponse, MessageDescription message, Type type, SerializerOption serializerOption)
 {
     if (type != null)
     {
         string name;
         string str2;
         if (serializerOption == SerializerOption.DataContractSerializer)
         {
             XmlQualifiedName rootElementName = XsdDataContractExporter.GetRootElementName(type);
             if (rootElementName == null)
             {
                 rootElementName = XsdDataContractExporter.GetSchemaTypeName(type);
             }
             if (!rootElementName.IsEmpty)
             {
                 name = rootElementName.Name;
                 str2 = rootElementName.Namespace;
             }
             else
             {
                 name = type.Name;
                 str2 = operation.DeclaringContract.Namespace;
             }
         }
         else
         {
             XmlTypeMapping mapping = XmlReflectionImporter.ImportTypeMapping(type);
             name = mapping.ElementName;
             str2 = mapping.Namespace;
         }
         MessagePartDescription item = new MessagePartDescription(NamingHelper.XmlName(name), str2) {
             Index = 0,
             Type = type
         };
         message.Body.Parts.Add(item);
     }
     if (isResponse)
     {
         SetReturnValue(message, operation);
     }
 }
コード例 #14
0
 public PartInfo(MessagePartDescription description, XmlDictionaryString dictionaryName, XmlDictionaryString dictionaryNamespace, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
 {
     _dictionaryName = dictionaryName;
     _dictionaryNamespace = dictionaryNamespace;
     _itemName = itemName;
     _itemNamespace = itemNamespace;
     _description = description;
     if (description.Type.IsArray)
     {
         _isArray = true;
         _typeCode = description.Type.GetElementType().GetTypeCode();
     }
     else
     {
         _isArray = false;
         _typeCode = description.Type.GetTypeCode();
     }
 }
コード例 #15
0
        private void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, object returnValue, object[] parameters)
        {
            if (serializer == null)
            {
                return;
            }

            bool hasReturnValue = IsValidReturnValue(returnPart);
            object[] bodyParameters = new object[bodyParts.Count + (hasReturnValue ? 1 : 0)];
            int paramIndex = 0;

            if (hasReturnValue)
                bodyParameters[paramIndex++] = returnValue;

            for (int i = 0; i < bodyParts.Count; i++)
                bodyParameters[paramIndex++] = parameters[bodyParts[i].Index];

            serializer.Serialize(writer, bodyParameters, null);
        }
コード例 #16
0
        private static bool IsTypeSupported(MessagePartDescription bodyDescription)
        {
            Fx.Assert(bodyDescription != null, "");
            Type type = bodyDescription.Type;
            if (type == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxMessagePartDescriptionMissingType, bodyDescription.Name, bodyDescription.Namespace)));

            if (bodyDescription.Multiple)
                return false;

            if (type == typeof(void))
                return true;
            if (type.IsEnum())
                return false;
            switch (type.GetTypeCode())
            {
                case TypeCode.Boolean:
                case TypeCode.DateTime:
                case TypeCode.Decimal:
                case TypeCode.Double:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.Single:
                case TypeCode.String:
                    return true;
                case TypeCode.Object:
                    if (type.IsArray && type.GetArrayRank() == 1 && IsArrayTypeSupported(type.GetElementType()))
                        return true;
                    break;
                default:
                    break;
            }
            return false;
        }
コード例 #17
0
 private static PartInfo AddToDictionary(XmlDictionary dictionary, MessagePartDescription part, bool isRpc)
 {
     Type type = part.Type;
     XmlDictionaryString itemName = null;
     XmlDictionaryString itemNamespace = null;
     if (type.IsArray && type != typeof(byte[]))
     {
         const string ns = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
         string name = GetArrayItemName(type.GetElementType());
         itemName = AddToDictionary(dictionary, name);
         itemNamespace = AddToDictionary(dictionary, ns);
     }
     return new PartInfo(part,
         AddToDictionary(dictionary, part.Name),
         AddToDictionary(dictionary, isRpc ? string.Empty : part.Namespace),
         itemName, itemNamespace);
 }
コード例 #18
0
		private void ExportDataContract (MessagePartDescription md)
		{
			if (data_contract_importer == null)
				data_contract_importer = md.DataContractImporter;
			else if (md.DataContractImporter != null && data_contract_importer != md.DataContractImporter)
				throw new Exception ("INTERNAL ERROR: should not happen");
			if (xml_serialization_importer == null)
				xml_serialization_importer = md.XmlSerializationImporter;
			else if (md.XmlSerializationImporter != null && xml_serialization_importer != md.XmlSerializationImporter)
				throw new Exception ("INTERNAL ERROR: should not happen");
		}
 /// <summary>
 /// Validates the message part description.
 /// </summary>
 /// <param name="messagePartDescription">The message part description.</param>
 private static void ValidateMessagePartDescription(MessagePartDescription messagePartDescription)
 {
     if (messagePartDescription != null)
     {
         ValidateJsonSerializableType(messagePartDescription.Type);
     }
 }
コード例 #20
0
ファイル: WebMessageFormatter.cs プロジェクト: LevNNN/mono
		protected XmlObjectSerializer GetSerializer (WebContentFormat msgfmt, bool isWrapped, MessagePartDescription part)
		{
			if (part.Type == typeof (void))
				return null; // no serialization should be done.

			switch (msgfmt) {
			case WebContentFormat.Xml:
				if (xml_serializer == null)
					xml_serializer = isWrapped ? new DataContractSerializer (part.Type, part.Name, part.Namespace) : new DataContractSerializer (part.Type);
				return xml_serializer;
			case WebContentFormat.Json:
				// FIXME: after name argument they are hack
				if (json_serializer == null)
					json_serializer = isWrapped ? new DataContractJsonSerializer (part.Type, BodyName ?? part.Name, null, 0x100000, false, null, true) : new DataContractJsonSerializer (part.Type);
				return json_serializer;
			default:
				throw new NotImplementedException (msgfmt.ToString ());
			}
		}
コード例 #21
0
 static internal XmlReflectionMember GetXmlReflectionMember(MessagePartDescription part, bool isRpc, bool isWrapped)
 {
     string ns = isRpc ? null : part.Namespace;
     MemberInfo additionalAttributesProvider = null;
     if (part.AdditionalAttributesProvider.MemberInfo != null)
         additionalAttributesProvider = part.AdditionalAttributesProvider.MemberInfo;
     XmlName memberName = string.IsNullOrEmpty(part.UniquePartName) ? null : new XmlName(part.UniquePartName, true /*isEncoded*/);
     XmlName elementName = part.XmlName;
     return GetXmlReflectionMember(memberName, elementName, ns, part.Type, additionalAttributesProvider, part.Multiple, isWrapped);
 }
コード例 #22
0
        protected void ExportMessagePart(WsdlNS.Message message, MessagePartDescription part, XmlQualifiedName typeName, XmlSchemaType xsdType, bool isOptional, bool isNillable, bool skipSchemaExport, bool generateElement, string wrapperNs, XmlSchemaSequence wrapperSequence, XmlSchemaSet schemaSet)
        {
            if (IsNullOrEmpty(typeName) && xsdType == null)
                return;
#if DEBUG
            if (xsdType == null)
                Fx.Assert(NamingHelper.IsValidNCName(typeName.Name), "Name value has to be a valid NCName.");
#endif
            string elementName = part.Name;
            string partName = string.IsNullOrEmpty(part.UniquePartName) ? elementName : part.UniquePartName;

            WsdlNS.MessagePart wsdlPart = null;
            if (generateElement)
            {
                if (wrapperSequence != null)
                {
                    if (!skipSchemaExport)
                        ExportLocalElement(wrapperNs, partName, part.Namespace, typeName, xsdType, part.Multiple, isOptional, isNillable, wrapperSequence, schemaSet);
                }
                else
                {
                    if (!skipSchemaExport)
                        ExportGlobalElement(elementName, part.Namespace, isNillable, typeName, xsdType, schemaSet);
                    wsdlPart = AddMessagePart(message, partName, new XmlQualifiedName(elementName, part.Namespace), XmlQualifiedName.Empty);
                }
            }
            else
            {
                if (String.IsNullOrEmpty(typeName.Name))
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxAnonymousTypeNotSupported, message.Name, partName)));

                wsdlPart = AddMessagePart(message, partName, XmlQualifiedName.Empty, typeName);
            }
            if (wsdlPart != null)
            {
                part.UniquePartName = wsdlPart.Name;
            }
        }
コード例 #23
0
        private object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, object[] parameters, bool isRequest)
        {
            try
            {
                if (reader == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
                if (parameters == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
                object returnValue = null;
                if (serializer == null)
                {
                    return null;
                }
                if (reader.NodeType == XmlNodeType.EndElement)
                    return null;

                object[] bodyParameters = (object[])serializer.Deserialize(reader);
                int paramIndex = 0;
                if (IsValidReturnValue(returnPart))
                    returnValue = bodyParameters[paramIndex++];

                for (int i = 0; i < bodyParts.Count; i++)
                    parameters[bodyParts[i].Index] = bodyParameters[paramIndex++];
                return returnValue;
            }
            catch (InvalidOperationException e)
            {
                // all exceptions from XmlSerializer get wrapped in InvalidOperationException,
                // so we must be conservative and never turn this into a fault
                string resourceKey = isRequest ? SR.SFxErrorDeserializingRequestBody : SR.SFxErrorDeserializingReplyBody;

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                    SR.Format(resourceKey, OperationName), e));
            }
        }
コード例 #24
0
ファイル: BaseMessagesFormatter.cs プロジェクト: nekresh/mono
		XmlObjectSerializer GetSerializer (MessagePartDescription partDesc)
		{
			if (!serializers.ContainsKey (partDesc))
				serializers [partDesc] = new DataContractSerializer (
					partDesc.Type, partDesc.Name, partDesc.Namespace, OperationKnownTypes);
			return serializers [partDesc];
		}
コード例 #25
0
        void ValidateExistingOrSetNewProtectionLevel(MessagePartDescription part, MessageDescription message, OperationDescription operation, ContractDescription contract, ProtectionLevel newProtectionLevel)
        {
            ProtectionLevel existingProtectionLevel;

            if (part != null && part.HasProtectionLevel)
            {
                existingProtectionLevel = part.ProtectionLevel;
            }
            else if (message.HasProtectionLevel)
            {
                existingProtectionLevel = message.ProtectionLevel;
            }
            else if (operation.HasProtectionLevel)
            {
                existingProtectionLevel = operation.ProtectionLevel;
            }
            else
            {
                if (part != null)
                {
                    part.ProtectionLevel = newProtectionLevel;
                }
                else
                {
                    message.ProtectionLevel = newProtectionLevel;
                }
                existingProtectionLevel = newProtectionLevel;
            }

            if (existingProtectionLevel != newProtectionLevel)
            {
                if (part != null && !part.HasProtectionLevel)
                {
                    part.ProtectionLevel = newProtectionLevel;
                }
                else if (part == null && !message.HasProtectionLevel)
                {
                    message.ProtectionLevel = newProtectionLevel;
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.CannotImportProtectionLevelForContract, contract.Name, contract.Namespace)));
                }
            }
        }
コード例 #26
0
ファイル: BaseMessagesFormatter.cs プロジェクト: nekresh/mono
			void WriteMessagePart (
				XmlDictionaryWriter writer, MessageBodyDescription desc, MessagePartDescription partDesc, object obj)
			{
				parent.GetSerializer (partDesc).WriteObject (writer, obj);
			}
コード例 #27
0
 /// <summary>
 /// Validate message part description
 /// </summary>
 /// <param name="pd"></param>
 private void ValidateMessagePartDescription(MessagePartDescription pd)
 {
     if (pd != null)
         this.ValidateIsIGraphable(pd.Type);
 }
コード例 #28
0
ファイル: BaseMessagesFormatter.cs プロジェクト: nekresh/mono
		public bool IsValidReturnValue (MessagePartDescription part)
		{
			return part != null && part.Type != typeof (void);
		}
コード例 #29
0
		XmlSchemaElement GetSchemaElementForPart (MessagePartDescription part, XmlSchema schema)
		{
			XmlSchemaElement element = new XmlSchemaElement ();

			element.Name = part.Name;
			XsdExporter.Export (part.Type);
			element.SchemaTypeName = XsdExporter.GetSchemaTypeName (part.Type);
			AddImport (schema, element.SchemaTypeName.Namespace);

			//FIXME: nillable, minOccurs
			if (XsdExporter.GetSchemaType (part.Type) is XmlSchemaComplexType ||
				part.Type == typeof (string))
				element.IsNillable = true;
			element.MinOccurs = 0;

			return element;
		}
        /// <summary>
        /// Create operation corresponding to given DomainService operation.
        /// </summary>
        /// <param name="declaringContract">Contract to which operation will belong.</param>
        /// <param name="operation">DomainService operation.</param>
        /// <returns>Created operation.</returns>
        private static OperationDescription CreateOperationDescription(ContractDescription declaringContract, DomainOperationEntry operation)
        {
            OperationDescription operationDesc = new OperationDescription(operation.Name, declaringContract);

            // Propagate behaviors.
            foreach (IOperationBehavior behavior in operation.Attributes.OfType<IOperationBehavior>())
            {
                operationDesc.Behaviors.Add(behavior);
            }

            // Add standard web behaviors behaviors.
            if ((operation.Operation == DomainOperation.Query && ((QueryAttribute)operation.OperationAttribute).HasSideEffects) ||
                (operation.Operation == DomainOperation.Invoke && ((InvokeAttribute)operation.OperationAttribute).HasSideEffects))
            {
                // For operations with side-effects i.e. with WebInvoke attribute, we need to build a default GET like
                // URI template so that, the parameter processing is taken care of by the WebHttpBehavior selector.
                WebInvokeAttribute attrib = ServiceUtils.EnsureBehavior<WebInvokeAttribute>(operationDesc);
                if (attrib.UriTemplate == null)
                {
                    attrib.UriTemplate = ODataEndpointFactory.BuildDefaultUriTemplate(operation);
                }
            }
            else
            {
                ServiceUtils.EnsureBehavior<WebGetAttribute>(operationDesc);
            }

            string action = ServiceUtils.GetRequestMessageAction(declaringContract, operationDesc.Name, null);

            // Define operation input.
            MessageDescription inputMessageDesc = new MessageDescription(action, MessageDirection.Input);
            inputMessageDesc.Body.WrapperName = operationDesc.Name;
            inputMessageDesc.Body.WrapperNamespace = ServiceUtils.DefaultNamespace;

            for (int i = 0; i < operation.Parameters.Count; i++)
            {
                DomainOperationParameter parameter = operation.Parameters[i];

                MessagePartDescription parameterPartDesc = new MessagePartDescription(parameter.Name, ServiceUtils.DefaultNamespace)
                {
                    Index = i,
                    Type = TypeUtils.GetClientType(parameter.ParameterType)
                };
                inputMessageDesc.Body.Parts.Add(parameterPartDesc);
            }

            operationDesc.Messages.Add(inputMessageDesc);

            // Define operation output.
            string responseAction = ServiceUtils.GetResponseMessageAction(declaringContract, operationDesc.Name, null);

            MessageDescription outputMessageDesc = new MessageDescription(responseAction, MessageDirection.Output);
            outputMessageDesc.Body.WrapperName = operationDesc.Name + "Response";
            outputMessageDesc.Body.WrapperNamespace = ServiceUtils.DefaultNamespace;

            if (operation.ReturnType != typeof(void))
            {
                outputMessageDesc.Body.ReturnValue = new MessagePartDescription(operationDesc.Name + "Result", ServiceUtils.DefaultNamespace)
                {
                    Type = TypeUtils.GetClientType(operation.ReturnType)
                };
            }
            operationDesc.Messages.Add(outputMessageDesc);

            return operationDesc;
        }