// Assumption: gets called exactly once per operation void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (partInfoTable != null && partInfoTable.Count > 0) { Dictionary <XmlMembersMapping, XmlMembersMapping> alreadyExported = new Dictionary <XmlMembersMapping, XmlMembersMapping>(); foreach (MessageDescription message in context.Operation.Messages) { foreach (MessageHeaderDescription header in message.Headers) { GeneratePartType(alreadyExported, header, header.Namespace); } MessageBodyDescription body = message.Body; bool isWrapped = (body.WrapperName != null); if (OperationFormatter.IsValidReturnValue(body.ReturnValue)) { GeneratePartType(alreadyExported, body.ReturnValue, isWrapped ? body.WrapperNamespace : body.ReturnValue.Namespace); } foreach (MessagePartDescription part in body.Parts) { GeneratePartType(alreadyExported, part, isWrapped ? body.WrapperNamespace : part.Namespace); } } } XmlSerializerOperationBehavior xmlSerializerOperationBehavior = context.Operation.Behaviors.Find <XmlSerializerOperationBehavior>() as XmlSerializerOperationBehavior; if (xmlSerializerOperationBehavior == null) { return; } XmlSerializerFormatAttribute xmlSerializerFormatAttribute = (xmlSerializerOperationBehavior == null) ? new XmlSerializerFormatAttribute() : xmlSerializerOperationBehavior.XmlSerializerFormatAttribute; OperationFormatStyle style = xmlSerializerFormatAttribute.Style; operationGenerator.GenerateOperation(context, ref style, xmlSerializerFormatAttribute.IsEncoded, new WrappedBodyTypeGenerator(context), new Dictionary <MessagePartDescription, ICollection <CodeTypeReference> >()); context.ServiceContractGenerator.AddReferencedAssembly(typeof(System.Xml.Serialization.XmlTypeAttribute).Assembly); xmlSerializerFormatAttribute.Style = style; context.SyncMethod.CustomAttributes.Add(OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, xmlSerializerFormatAttribute)); AddKnownTypes(context.SyncMethod.CustomAttributes, xmlSerializerFormatAttribute.IsEncoded ? SoapExporter.IncludeMetadata : XmlExporter.IncludeMetadata); DataContractSerializerOperationGenerator.UpdateTargetCompileUnit(context, this.options.CodeCompileUnit); }
void IOperationContractGenerationExtension.GenerateOperation(OperationContractGenerationContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if ((this.partInfoTable != null) && (this.partInfoTable.Count > 0)) { Dictionary <XmlMembersMapping, XmlMembersMapping> alreadyExported = new Dictionary <XmlMembersMapping, XmlMembersMapping>(); foreach (MessageDescription description in context.Operation.Messages) { foreach (MessageHeaderDescription description2 in description.Headers) { this.GeneratePartType(alreadyExported, description2); } if (OperationFormatter.IsValidReturnValue(description.Body.ReturnValue)) { this.GeneratePartType(alreadyExported, description.Body.ReturnValue); } foreach (MessagePartDescription description3 in description.Body.Parts) { this.GeneratePartType(alreadyExported, description3); } } } XmlSerializerOperationBehavior behavior = context.Operation.Behaviors.Find <XmlSerializerOperationBehavior>(); if (behavior != null) { XmlSerializerFormatAttribute attribute = (behavior == null) ? new XmlSerializerFormatAttribute() : behavior.XmlSerializerFormatAttribute; OperationFormatStyle style = attribute.Style; this.operationGenerator.GenerateOperation(context, ref style, attribute.IsEncoded, new WrappedBodyTypeGenerator(context), new Dictionary <MessagePartDescription, ICollection <CodeTypeReference> >()); context.ServiceContractGenerator.AddReferencedAssembly(typeof(XmlTypeAttribute).Assembly); attribute.Style = style; context.SyncMethod.CustomAttributes.Add(System.ServiceModel.Description.OperationGenerator.GenerateAttributeDeclaration(context.Contract.ServiceContractGenerator, attribute)); this.AddKnownTypes(context.SyncMethod.CustomAttributes, attribute.IsEncoded ? this.SoapExporter.IncludeMetadata : this.XmlExporter.IncludeMetadata); DataContractSerializerOperationGenerator.UpdateTargetCompileUnit(context, this.options.CodeCompileUnit); } }
public WrappedBodyTypeGenerator(DataContractSerializerOperationGenerator dataContractSerializerOperationGenerator, OperationContractGenerationContext context) { this.context = context; this.dataContractSerializerOperationGenerator = dataContractSerializerOperationGenerator; }