// Assumption: gets called exactly once per operation void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context) { DataContractSerializerOperationBehavior DataContractSerializerOperationBehavior = context.Operation.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior; DataContractFormatAttribute dataContractFormatAttribute = (DataContractSerializerOperationBehavior == null) ? new DataContractFormatAttribute() : DataContractSerializerOperationBehavior.DataContractFormatAttribute; OperationFormatStyle style = dataContractFormatAttribute.Style; operationGenerator.GenerateOperation(context, ref style, false /*isEncoded*/, new WrappedBodyTypeGenerator(this, context), knownTypes); dataContractFormatAttribute.Style = style; if (dataContractFormatAttribute.Style != TypeLoader.DefaultDataContractFormatAttribute.Style) { context.SyncMethod.CustomAttributes.Add(OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, dataContractFormatAttribute)); } if (knownTypes != null) { Dictionary <CodeTypeReference, object> operationKnownTypes = new Dictionary <CodeTypeReference, object>(new CodeTypeReferenceComparer()); foreach (MessageDescription message in context.Operation.Messages) { foreach (MessagePartDescription part in message.Body.Parts) { AddKnownTypesForPart(context, part, operationKnownTypes); } foreach (MessageHeaderDescription header in message.Headers) { AddKnownTypesForPart(context, header, operationKnownTypes); } if (OperationFormatter.IsValidReturnValue(message.Body.ReturnValue)) { AddKnownTypesForPart(context, message.Body.ReturnValue, operationKnownTypes); } } } UpdateTargetCompileUnit(context, this.codeCompileUnit); }
void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context) { DataContractSerializerOperationBehavior behavior = context.Operation.Behaviors.Find <DataContractSerializerOperationBehavior>(); DataContractFormatAttribute attribute = (behavior == null) ? new DataContractFormatAttribute() : behavior.DataContractFormatAttribute; OperationFormatStyle style = attribute.Style; this.operationGenerator.GenerateOperation(context, ref style, false, new WrappedBodyTypeGenerator(this, context), this.knownTypes); attribute.Style = style; if (attribute.Style != TypeLoader.DefaultDataContractFormatAttribute.Style) { context.SyncMethod.CustomAttributes.Add(System.ServiceModel.Description.OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, attribute)); } if (this.knownTypes != null) { Dictionary <CodeTypeReference, object> operationKnownTypes = new Dictionary <CodeTypeReference, object>(new CodeTypeReferenceComparer()); foreach (MessageDescription description in context.Operation.Messages) { foreach (MessagePartDescription description2 in description.Body.Parts) { this.AddKnownTypesForPart(context, description2, operationKnownTypes); } foreach (MessageHeaderDescription description3 in description.Headers) { this.AddKnownTypesForPart(context, description3, operationKnownTypes); } if (OperationFormatter.IsValidReturnValue(description.Body.ReturnValue)) { this.AddKnownTypesForPart(context, description.Body.ReturnValue, operationKnownTypes); } } } UpdateTargetCompileUnit(context, this.codeCompileUnit); }
protected override void ExportBody(int messageIndex, object state) { XmlSchemaType type; MessageDescription messageDescription = base.operation.Messages[messageIndex]; Message message = base.ExportedMessages.WsdlMessages[new MessageContractExporter.MessageDescriptionDictionaryKey(base.contractContext.Contract, messageDescription)]; DataContractFormatAttribute dataContractFormatAttribute = ((DataContractSerializerOperationBehavior)base.extension).DataContractFormatAttribute; XmlSchemaSequence wrapperSequence = null; bool flag = messageDescription.Body.WrapperName != null; if ((dataContractFormatAttribute.Style == OperationFormatStyle.Document) && flag) { wrapperSequence = base.ExportWrappedPart(message, messageDescription.Body.WrapperName, messageDescription.Body.WrapperNamespace, base.SchemaSet, false); } if (OperationFormatter.IsValidReturnValue(messageDescription.Body.ReturnValue)) { XmlQualifiedName typeName = base.ExportType(messageDescription.Body.ReturnValue.Type, messageDescription.Body.ReturnValue.Name, base.operation.Name, out type); base.ExportMessagePart(message, messageDescription.Body.ReturnValue, typeName, type, true, IsTypeNullable(messageDescription.Body.ReturnValue.Type), false, dataContractFormatAttribute.Style != OperationFormatStyle.Rpc, messageDescription.Body.WrapperNamespace, wrapperSequence, base.SchemaSet); } foreach (MessagePartDescription description2 in messageDescription.Body.Parts) { XmlQualifiedName name2 = base.ExportType(description2.Type, description2.Name, base.operation.Name, out type); base.ExportMessagePart(message, description2, name2, type, true, IsTypeNullable(description2.Type), false, dataContractFormatAttribute.Style != OperationFormatStyle.Rpc, messageDescription.Body.WrapperNamespace, wrapperSequence, base.SchemaSet); } if (dataContractFormatAttribute.Style == OperationFormatStyle.Rpc) { base.AddParameterOrder(messageDescription); } }
public DataContractSerializerOperationBehavior( OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) { this.format = dataContractFormatAttribute; this.operation = operation; MaxItemsInObjectGraph = int.MaxValue; }
public DataContractMessagesFormatter(OperationDescription desc, DataContractFormatAttribute attr) : base(desc) { #if !MOBILE this.serializerBehavior = desc.Behaviors.Find <DataContractSerializerOperationBehavior>(); #endif this.attr = attr; }
public DataContractSerializerOperationBehavior ( OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) { this.format = dataContractFormatAttribute; this.operation = operation; MaxItemsInObjectGraph = int.MaxValue; }
public static TypedMessageConverter Create( Type type, string action, string defaultNamespace, DataContractFormatAttribute formatterAttribute) { return(new DefaultTypedMessageConverter( new DataContractMessagesFormatter( MessageContractToMessagesDescription(type, defaultNamespace, action), formatterAttribute))); }
private static bool DetermineXmlFormat(HttpOperationDescription operation) { Fx.Assert(operation != null, "The 'operation' parameter should not be null."); DataContractFormatAttribute dataContract = null; XmlSerializerFormatAttribute xmlSerializer = null; foreach (Attribute attribute in operation.Attributes) { if (dataContract == null) { dataContract = attribute as DataContractFormatAttribute; } if (xmlSerializer == null) { xmlSerializer = attribute as XmlSerializerFormatAttribute; } } if (xmlSerializer == null && dataContract != null) { return(false); } ContractDescription contract = operation.DeclaringContract; if (contract != null) { Type contractType = contract.ContractType; if (contractType != null) { foreach (Attribute attribute in contractType.GetCustomAttributes(true).Cast <Attribute>()) { if (dataContract == null) { dataContract = attribute as DataContractFormatAttribute; } if (xmlSerializer == null) { xmlSerializer = attribute as XmlSerializerFormatAttribute; } } if (xmlSerializer == null && dataContract != null) { return(false); } } } return(true); }
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { dispatchOperation.SerializeReply = true; dispatchOperation.DeserializeRequest = true; var dataContractFormatAttribute = operationDescription.SyncMethod.GetCustomAttributes(typeof(DataContractFormatAttribute), true).FirstOrDefault() as DataContractFormatAttribute; if (null == dataContractFormatAttribute) { dataContractFormatAttribute = new DataContractFormatAttribute(); } var dataContractSerializerOperationBehavior = operationDescription.Behaviors.Find <DataContractSerializerOperationBehavior>(); dispatchOperation.Formatter = new CompressionMessageFormatter(this.Algorithm, operationDescription, dataContractFormatAttribute, dataContractSerializerOperationBehavior); }
private MessageInfo CreateMessageInfo(DataContractFormatAttribute dataContractFormatAttribute, MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory) { if (messageDescription.IsUntypedMessage) { return(null); } MessageInfo messageInfo = new MessageInfo(); MessageBodyDescription body = messageDescription.Body; if (body.WrapperName != null) { messageInfo.WrapperName = AddToDictionary(body.WrapperName); messageInfo.WrapperNamespace = AddToDictionary(body.WrapperNamespace); } MessagePartDescriptionCollection parts = body.Parts; messageInfo.BodyParts = new PartInfo[parts.Count]; for (int i = 0; i < parts.Count; i++) { messageInfo.BodyParts[i] = CreatePartInfo(parts[i], dataContractFormatAttribute.Style, serializerFactory); } if (IsValidReturnValue(messageDescription.Body.ReturnValue)) { messageInfo.ReturnPart = CreatePartInfo(messageDescription.Body.ReturnValue, dataContractFormatAttribute.Style, serializerFactory); } messageInfo.HeaderDescriptionTable = new MessageHeaderDescriptionTable(); messageInfo.HeaderParts = new PartInfo[messageDescription.Headers.Count]; for (int i = 0; i < messageDescription.Headers.Count; i++) { MessageHeaderDescription headerDescription = messageDescription.Headers[i]; if (headerDescription.IsUnknownHeaderCollection) { messageInfo.UnknownHeaderDescription = headerDescription; } else { ValidateDataContractType(headerDescription.Type); messageInfo.HeaderDescriptionTable.Add(headerDescription.Name, headerDescription.Namespace, headerDescription); } messageInfo.HeaderParts[i] = CreatePartInfo(headerDescription, OperationFormatStyle.Document, serializerFactory); } messageInfo.AnyHeaders = messageInfo.UnknownHeaderDescription != null || messageInfo.HeaderDescriptionTable.Count > 0; return(messageInfo); }
private MessageInfo CreateMessageInfo(DataContractFormatAttribute dataContractFormatAttribute, MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory) { if (messageDescription.IsUntypedMessage) { return(null); } MessageInfo info = new MessageInfo(); MessageBodyDescription body = messageDescription.Body; if (body.WrapperName != null) { info.WrapperName = base.AddToDictionary(body.WrapperName); info.WrapperNamespace = base.AddToDictionary(body.WrapperNamespace); } MessagePartDescriptionCollection parts = body.Parts; info.BodyParts = new PartInfo[parts.Count]; for (int i = 0; i < parts.Count; i++) { info.BodyParts[i] = this.CreatePartInfo(parts[i], dataContractFormatAttribute.Style, serializerFactory); } if (OperationFormatter.IsValidReturnValue(messageDescription.Body.ReturnValue)) { info.ReturnPart = this.CreatePartInfo(messageDescription.Body.ReturnValue, dataContractFormatAttribute.Style, serializerFactory); } info.HeaderDescriptionTable = new OperationFormatter.MessageHeaderDescriptionTable(); info.HeaderParts = new PartInfo[messageDescription.Headers.Count]; for (int j = 0; j < messageDescription.Headers.Count; j++) { MessageHeaderDescription message = messageDescription.Headers[j]; if (message.IsUnknownHeaderCollection) { info.UnknownHeaderDescription = message; } else { this.ValidateDataContractType(message.Type); info.HeaderDescriptionTable.Add(message.Name, message.Namespace, message); } info.HeaderParts[j] = this.CreatePartInfo(message, OperationFormatStyle.Document, serializerFactory); } info.AnyHeaders = (info.UnknownHeaderDescription != null) || (info.HeaderDescriptionTable.Count > 0); return(info); }
// FIXME: this should be refactored and eliminated. // XmlSerializerFormatAttribute and DataContractFormatAttribute // should be handled at ContractDescription.GetContract (to fill // IOperationBehavior for each). // // Fixing the issue above should also fix "Formatter is already filled at initial state" issue described in EndpointDispatcher.cs and ContractDescription.cs. public static BaseMessagesFormatter Create(OperationDescription desc) { MethodInfo attrProvider = desc.SyncMethod ?? desc.BeginMethod; object [] attrs; attrs = attrProvider.GetCustomAttributes(typeof(XmlSerializerFormatAttribute), false); if (attrs != null && attrs.Length > 0) { return(new XmlMessagesFormatter(desc, (XmlSerializerFormatAttribute)attrs [0])); } attrs = attrProvider.GetCustomAttributes(typeof(DataContractFormatAttribute), false); DataContractFormatAttribute dataAttr = null; if (attrs != null && attrs.Length > 0) { dataAttr = (DataContractFormatAttribute)attrs [0]; } return(new DataContractMessagesFormatter(desc, dataAttr)); }
public DataContractSerializerOperationFormatter(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) : base(description, dataContractFormatAttribute.Style == OperationFormatStyle.Rpc, false/*isEncoded*/) { if (description == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); _serializerFactory = serializerFactory ?? new DataContractSerializerOperationBehavior(description); foreach (Type type in description.KnownTypes) { if (_knownTypes == null) _knownTypes = new List<Type>(); if (type == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxKnownTypeNull, description.Name))); ValidateDataContractType(type); _knownTypes.Add(type); } requestMessageInfo = CreateMessageInfo(dataContractFormatAttribute, RequestDescription, _serializerFactory); if (ReplyDescription != null) replyMessageInfo = CreateMessageInfo(dataContractFormatAttribute, ReplyDescription, _serializerFactory); }
public DataContractMessagesFormatter(MessageDescriptionCollection messages, DataContractFormatAttribute attr) : base(messages) { this.attr = attr; }
public DataContractSerializerOperationFormatter(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) : base(description, dataContractFormatAttribute.Style == OperationFormatStyle.Rpc, false) { if (description == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); } this.serializerFactory = serializerFactory ?? new DataContractSerializerOperationBehavior(description); foreach (System.Type type in description.KnownTypes) { if (this.knownTypes == null) { this.knownTypes = new List <System.Type>(); } if (type == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxKnownTypeNull", new object[] { description.Name }))); } this.ValidateDataContractType(type); this.knownTypes.Add(type); } this.requestMessageInfo = this.CreateMessageInfo(dataContractFormatAttribute, base.RequestDescription, this.serializerFactory); if (base.ReplyDescription != null) { this.replyMessageInfo = this.CreateMessageInfo(dataContractFormatAttribute, base.ReplyDescription, this.serializerFactory); } }
public static TypedMessageConverter Create(Type messageContract, String action, String defaultNamespace, DataContractFormatAttribute formatterAttribute) { if (messageContract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageContract")); } if (!messageContract.IsDefined(typeof(MessageContractAttribute), false)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.SFxMessageContractAttributeRequired, messageContract), "messageContract")); } if (defaultNamespace == null) { defaultNamespace = NamingHelper.DefaultNamespace; } return(new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, action))); }
/// <summary> /// Initializes a new instance of the <see cref="SerializationLoggingOperationBehavior" /> class. /// </summary> /// <param name="operation">The operation being examined.</param> /// <param name="dataContractFormatAttribute"> /// The run-time object that exposes customization properties for the operation described by <paramref name="operation" />. /// </param> public SerializationLoggingOperationBehavior( OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) : base(operation, dataContractFormatAttribute) { }
public DataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) { _dataContractFormatAttribute = dataContractFormatAttribute ?? new DataContractFormatAttribute(); _operation = operation; }
public DataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) { _dataContractFormatAttribute = dataContractFormatAttribute ?? new DataContractFormatAttribute(); _operation = operation; }
internal ExtensionData(DataContractFormatAttribute dcFormatAttr) { this.dcFormatAttr = dcFormatAttr; }
private MessageInfo CreateMessageInfo(DataContractFormatAttribute dataContractFormatAttribute, MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory) { if (messageDescription.IsUntypedMessage) return null; MessageInfo messageInfo = new MessageInfo(); MessageBodyDescription body = messageDescription.Body; if (body.WrapperName != null) { messageInfo.WrapperName = AddToDictionary(body.WrapperName); messageInfo.WrapperNamespace = AddToDictionary(body.WrapperNamespace); } MessagePartDescriptionCollection parts = body.Parts; messageInfo.BodyParts = new PartInfo[parts.Count]; for (int i = 0; i < parts.Count; i++) messageInfo.BodyParts[i] = CreatePartInfo(parts[i], dataContractFormatAttribute.Style, serializerFactory); if (IsValidReturnValue(messageDescription.Body.ReturnValue)) messageInfo.ReturnPart = CreatePartInfo(messageDescription.Body.ReturnValue, dataContractFormatAttribute.Style, serializerFactory); messageInfo.HeaderDescriptionTable = new MessageHeaderDescriptionTable(); messageInfo.HeaderParts = new PartInfo[messageDescription.Headers.Count]; for (int i = 0; i < messageDescription.Headers.Count; i++) { MessageHeaderDescription headerDescription = messageDescription.Headers[i]; if (headerDescription.IsUnknownHeaderCollection) messageInfo.UnknownHeaderDescription = headerDescription; else { ValidateDataContractType(headerDescription.Type); messageInfo.HeaderDescriptionTable.Add(headerDescription.Name, headerDescription.Namespace, headerDescription); } messageInfo.HeaderParts[i] = CreatePartInfo(headerDescription, OperationFormatStyle.Document, serializerFactory); } messageInfo.AnyHeaders = messageInfo.UnknownHeaderDescription != null || messageInfo.HeaderDescriptionTable.Count > 0; return messageInfo; }
public LoadBalanceDataContractSerializationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) : base(operation, dataContractFormatAttribute) { base.DataContractResolver = new LoadBalanceDataContractResolver(); base.DataContractSurrogate = new LoadBalanceDataContractSurrogate(); }
/// <summary> /// متد سازنده /// </summary> /// <param name="operation">یک OperationDescription که نماینگار Operation است</param> /// <param name="dataContractFormatAttribute">یک DataContractFormatAttribute برای کنترل عمل serialization</param> public NetDataContractOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) : base(operation, dataContractFormatAttribute) { }
public CustomDataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) : base(operation, dataContractFormatAttribute) { }
public static TypedMessageConverter Create(System.Type messageContract, string action, string defaultNamespace, DataContractFormatAttribute formatterAttribute) { if (messageContract == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageContract")); } if (!messageContract.IsDefined(typeof(MessageContractAttribute), false)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("SFxMessageContractAttributeRequired", new object[] { messageContract }), "messageContract")); } if (defaultNamespace == null) { defaultNamespace = "http://tempuri.org/"; } return(new XmlMessageConverter(GetOperationFormatter(messageContract, formatterAttribute, defaultNamespace, action))); }
public static TypedMessageConverter Create(Type messageContract, string action, DataContractFormatAttribute formatterAttribute) { return(Create(messageContract, action, null, formatterAttribute)); }
public DataContractMessagesFormatter(OperationDescription desc, DataContractFormatAttribute attr) : base(desc) { this.attr = attr; }
public DataContractSerializerOperationFormatter(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) : base(description, dataContractFormatAttribute.Style == OperationFormatStyle.Rpc, false /*isEncoded*/) { if (description == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description)); } _serializerFactory = serializerFactory ?? new DataContractSerializerOperationBehavior(description); foreach (Type type in description.KnownTypes) { if (_knownTypes == null) { _knownTypes = new List <Type>(); } if (type == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxKnownTypeNull, description.Name))); } ValidateDataContractType(type); _knownTypes.Add(type); } requestMessageInfo = CreateMessageInfo(dataContractFormatAttribute, RequestDescription, _serializerFactory); if (ReplyDescription != null) { replyMessageInfo = CreateMessageInfo(dataContractFormatAttribute, ReplyDescription, _serializerFactory); } }
public static TypedMessageConverter Create( Type type, string action, DataContractFormatAttribute formatterAttribute) { return(Create(type, action, TempUri, formatterAttribute)); }
internal DataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute, bool builtInOperationBehavior) : this(operation, dataContractFormatAttribute) { _builtInOperationBehavior = builtInOperationBehavior; }
public CompressionMessageFormatter(CompressionAlgorithm algorithm, OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) { this.MessageCompressor = new MessageCompressor(algorithm); Type innerFormatterType = Type.GetType(DataContractSerializerOperationFormatterTypeName); var innerFormatter = Activator.CreateInstance(innerFormatterType, description, dataContractFormatAttribute, serializerFactory); this.InnerClientMessageFormatter = innerFormatter as IClientMessageFormatter; this.InnerDispatchMessageFormatter = innerFormatter as IDispatchMessageFormatter; }
internal DataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute, bool builtInOperationBehavior) : this(operation, dataContractFormatAttribute) { _builtInOperationBehavior = builtInOperationBehavior; }
public ReferencePreservingOperationBehavior(OperationDescription operationDescription, DataContractFormatAttribute dataContractFormatAttribute) : base(operationDescription, dataContractFormatAttribute) { // }