/// <summary> /// When the contract is exported, we add "CyclicReferencesAwareAttribute" to the export so that the WSDL importer knows /// where to add the attribute on the client side. Yes, I'll admit it's a little kludge, but it seems to work. /// </summary> /// <param name="exporter"></param> /// <param name="context"></param> public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { if (_contractDescription != null) { context.WsdlPortType.Documentation = "CyclicReferencesAwareAttribute"; } else { Operation operation = context.GetOperation(_operationDescription); if (operation != null) { operation.Documentation = "CyclicReferencesAwareAttribute"; } } }
void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { // This is either for a service contract or operation, so set documentation accordingly. if (_contractDescription != null) { // Attribute was applied to a contract. context.WsdlPortType.Documentation = this.Text; } else { // Attribute was applied to an operation. Operation operation = context.GetOperation(_operationDescription); if (operation != null) { operation.Documentation = this.Text; } } }
//<snippet1> // <snippet6> public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { // </snippet6> // <snippet5> // Add a custom DCAnnotationSurrogate to write data contract comments into the XSD. object dataContractExporter; XsdDataContractExporter xsdDCExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdDCExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdDCExporter); } else { xsdDCExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdDCExporter.Options == null) { xsdDCExporter.Options = new ExportOptions(); } xsdDCExporter.Options.DataContractSurrogate = new DCAnnotationSurrogate(); // </snippet5> // <snippet7> Console.WriteLine("Inside ExportContract"); if (context.Contract != null) { // Inside this block it is the contract-level comment attribute. // This.Text returns the string for the contract attribute. // Set the doc element; if this isn't done first, there is no XmlElement in the // DocumentElement property. context.WsdlPortType.Documentation = string.Empty; // Contract comments. XmlDocument owner = context.WsdlPortType.DocumentationElement.OwnerDocument; XmlElement summaryElement = Formatter.CreateSummaryElement(owner, this.Text); context.WsdlPortType.DocumentationElement.AppendChild(summaryElement); foreach (OperationDescription op in context.Contract.Operations) { Operation operation = context.GetOperation(op); object[] opAttrs = op.SyncMethod.GetCustomAttributes(typeof(WsdlDocumentationAttribute), false); if (opAttrs.Length == 1) { string opComment = ((WsdlDocumentationAttribute)opAttrs[0]).Text; // This.Text returns the string for the operation-level attributes. // Set the doc element; if this isn't done first, there is no XmlElement in the // DocumentElement property. operation.Documentation = String.Empty; // Operation C# triple comments. XmlDocument opOwner = operation.DocumentationElement.OwnerDocument; XmlElement newSummaryElement = Formatter.CreateSummaryElement(opOwner, opComment); operation.DocumentationElement.AppendChild(newSummaryElement); // Get returns information ParameterInfo returnValue = op.SyncMethod.ReturnParameter; object[] returnAttrs = returnValue.GetCustomAttributes(typeof(WsdlParameterDocumentationAttribute), false); if (returnAttrs.Length == 1) { // <returns>text.</returns> XmlElement returnsElement = Formatter.CreateReturnsElement( opOwner, ((WsdlParameterDocumentationAttribute)returnAttrs[0]).ParamComment ); operation.DocumentationElement.AppendChild(returnsElement); } // Get parameter information. ParameterInfo[] args = op.SyncMethod.GetParameters(); for (int i = 0; i < args.Length; i++) { object[] docAttrs = args[i].GetCustomAttributes(typeof(WsdlParameterDocumentationAttribute), false); if (docAttrs.Length != 0) { // <param name="Int1">Text.</param> XmlElement newParamElement = opOwner.CreateElement("param"); XmlAttribute paramName = opOwner.CreateAttribute("name"); paramName.Value = args[i].Name; newParamElement.InnerText = ((WsdlParameterDocumentationAttribute)docAttrs[0]).ParamComment; newParamElement.Attributes.Append(paramName); operation.DocumentationElement.AppendChild(newParamElement); } } } } } // </snippet7> }
public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { Debug.WriteLine("Inside ExportContract"); if (contractDescription != null) { // Inside this block it is the contract-level comment attribute. // This.Text returns the string for the contract attribute. // Set the doc element; if this isn't done first, there is no XmlElement in the // DocumentElement property. context.WsdlPortType.Documentation = string.Empty; // Contract comments. XmlDocument owner = context.WsdlPortType.DocumentationElement.OwnerDocument; XmlElement summaryElement = owner.CreateElement("summary"); summaryElement.InnerText = this.Text; context.WsdlPortType.DocumentationElement.AppendChild(summaryElement); } else { Operation operation = context.GetOperation(operationDescription); if (operation != null) { // We are dealing strictly with the operation here. // This.Text returns the string for the operation-level attributes. // Set the doc element; if this isn't done first, there is no XmlElement in the // DocumentElement property. operation.Documentation = String.Empty; // Operation C# triple comments. XmlDocument owner = operation.DocumentationElement.OwnerDocument; XmlElement newSummaryElement = owner.CreateElement("summary"); newSummaryElement.InnerText = this.Text; operation.DocumentationElement.AppendChild(newSummaryElement); // Get returns information ParameterInfo returnValue = operationDescription.SyncMethod.ReturnParameter; object[] returnAttrs = returnValue.GetCustomAttributes(typeof(WsdlParamOrReturnDocumentationAttribute), false); if (returnAttrs.Length != 0) { // <returns>text.</returns> XmlElement returnsElement = owner.CreateElement("returns"); returnsElement.InnerText = ((WsdlParamOrReturnDocumentationAttribute)returnAttrs[0]).ParamComment; operation.DocumentationElement.AppendChild(returnsElement); } // Get parameter information. ParameterInfo[] args = operationDescription.SyncMethod.GetParameters(); for (int i = 0; i < args.Length; i++) { object[] docAttrs = args[i].GetCustomAttributes(typeof(WsdlParamOrReturnDocumentationAttribute), false); if (docAttrs.Length == 1) { // <param name="Int1">Text.</param> XmlElement newParamElement = owner.CreateElement("param"); XmlAttribute paramName = owner.CreateAttribute("name"); paramName.Value = args[i].Name; newParamElement.InnerText = ((WsdlParamOrReturnDocumentationAttribute)docAttrs[0]).ParamComment; newParamElement.Attributes.Append(paramName); operation.DocumentationElement.AppendChild(newParamElement); } } } } }