ServiceEndpoint ImportBinding(WSBinding binding, WsdlContractConversionContext contract_context) { BeforeImport(); var sep = new ServiceEndpoint(contract_context.Contract); var custom = new CustomBinding(); custom.Name = binding.Name; custom.Namespace = binding.ServiceDescription.TargetNamespace; sep.Binding = custom; try { ImportPolicy(binding, sep); } catch (Exception ex) { // FIXME: Policy import is still experimental. AddWarning("Exception while trying to import policy for " + "binding `{0}': {1}", binding.Name, ex.Message); } var endpoint_context = new WsdlEndpointConversionContext( contract_context, sep, null, binding); foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.ImportEndpoint(this, endpoint_context); } return(sep); }
// // IWsdlExportExtension Implementation // public void ExportContract( WsdlExporter exporter, WsdlContractConversionContext context ) { // never called }
protected MessageContractExporter(WsdlExporter exporter, WsdlContractConversionContext context, OperationDescription operation, IOperationBehavior extension) { this.exporter = exporter; this.contractContext = context; this.operation = operation; this.extension = extension; }
void IWsdlImportExtension.ImportContract (WsdlImporter importer, WsdlContractConversionContext context) { if (!enabled) return; if (importer == null) throw new ArgumentNullException ("importer"); if (context == null) throw new ArgumentNullException ("context"); if (this.importer != null || this.context != null) throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call"); #if USE_DATA_CONTRACT_IMPORTER dc_importer = new XsdDataContractImporter (); schema_set_in_use = new XmlSchemaSet (); schema_set_in_use.Add (importer.XmlSchemas); foreach (WSDL wsdl in importer.WsdlDocuments) foreach (XmlSchema xs in wsdl.Types.Schemas) schema_set_in_use.Add (xs); dc_importer.Import (schema_set_in_use); #endif this.importer = importer; this.context = context; try { DoImportContract (); } finally { this.importer = null; this.context = null; } }
private void CallExportContract(WsdlContractConversionContext contractContext) { foreach (IWsdlExportExtension extension in contractContext.ExportExtensions) { this.CallExtension(contractContext, extension); } }
void IWsdlImportExtension.ImportContract (WsdlImporter importer, WsdlContractConversionContext context) { if (!enabled) return; if (importer == null) throw new ArgumentNullException ("importer"); if (context == null) throw new ArgumentNullException ("context"); if (this.importer != null || this.context != null) throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call"); dc_importer = new XsdDataContractImporter (); schema_set_in_use = new XmlSchemaSet (); schema_set_in_use.Add (importer.XmlSchemas); foreach (WSDL wsdl in importer.WsdlDocuments) foreach (XmlSchema xs in wsdl.Types.Schemas) schema_set_in_use.Add (xs); // commenting out this import operation, but might be required (I guess not). //dc_importer.Import (schema_set_in_use); schema_set_in_use.Compile (); this.importer = importer; this.context = context; try { DoImportContract (); } finally { this.importer = null; this.context = null; } }
void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext contractContext) { if (contractContext == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contractContext")); MessageContractImporter.ImportMessageContract(importer, contractContext, MessageContractImporter.XmlSerializerSchemaImporter.Get(importer)); }
/// <summary> /// When ExportContract is called to generate the necessary metadata, we inspect the service /// contract and build a list of parameters that we'll need to adjust the XSD for later. /// </summary> void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { _requiredParameter = new List<RequiredMessagePart>(); foreach (var operation in context.Contract.Operations) { var inputMessage = operation.Messages.Where(m => m.Direction == MessageDirection.Input).First(); var parameters = operation.SyncMethod.GetParameters(); Debug.Assert(parameters.Length == inputMessage.Body.Parts.Count); for (int i = 0; i < parameters.Length; i++) { object[] attributes = parameters[i].GetCustomAttributes(typeof(OptionalAttribute), false); if (attributes.Length == 0) { // The parameter has no [Optional] attribute, add it to the list of parameters // that we need to adjust the XML schema for later on. _requiredParameter.Add(new RequiredMessagePart() { Namespace = inputMessage.Body.Parts[i].Namespace, Message = operation.Name, Name = inputMessage.Body.Parts[i].Name }); } } } }
void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { if (!enabled) { return; } if (importer == null) { throw new ArgumentNullException("importer"); } if (context == null) { throw new ArgumentNullException("context"); } if (this.importer != null || this.context != null) { throw new SystemException("INTERNAL ERROR: unexpected recursion of ImportContract method call"); } this.importer = importer; this.context = context; try { DoImportContract(); } finally { this.importer = null; this.context = null; } }
internal WsdlEndpointConversionContext(WsdlContractConversionContext context, ServiceEndpoint endpoint, Port port, WSBinding wsdlBinding) { this.context = context; this.endpoint = endpoint; this.port = port; this.wsdl_binding = wsdlBinding; }
internal WsdlEndpointConversionContext (WsdlContractConversionContext context, ServiceEndpoint endpoint, Port port, WSBinding wsdlBinding) { this.context = context; this.endpoint = endpoint; this.port = port; this.wsdl_binding = wsdlBinding; }
void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext contractContext) { if (contractContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("contractContext")); } MessageContractImporter.ImportMessageContract(importer, contractContext, MessageContractImporter.XmlSerializerSchemaImporter.Get(importer)); }
void IWsdlImportExtension.ImportContract (WsdlImporter importer, WsdlContractConversionContext context) { if (!Enabled) return; impl.ImportContract (importer, context); }
void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { if (!Enabled) { return; } impl.ImportContract(importer, context); }
void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext) { if (exporter == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter"); } if (contractContext == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractContext"); } new DataContractSerializerMessageContractExporter(exporter, contractContext, this.operation, this).ExportMessageContract(); }
void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext) { if (exporter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter"); } if (contractContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractContext"); } new XmlSerializerMessageContractExporter(exporter, contractContext, this.reflector.Operation, this).ExportMessageContract(); }
public ServiceEndpoint ImportEndpoint(Port wsdlPort) { foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.BeforeImport(wsdl_documents, xmlschemas, policies); } //Get the corresponding contract //via the PortType WSBinding wsb = wsdlPort.Service.ServiceDescription.Bindings [wsdlPort.Binding.Name]; if (wsb == null) { //FIXME throw new Exception(String.Format("Binding named {0} not found.", wsdlPort.Binding.Name)); } SMBinding binding = ImportBinding(wsb); PortType port_type = null; foreach (WSServiceDescription sd in wsdl_documents) { port_type = sd.PortTypes [wsb.Type.Name]; if (port_type != null) { break; } } if (port_type == null) { //FIXME throw new Exception(String.Format("PortType named {0} not found.", wsb.Type.Name)); } ContractDescription contract = ImportContract(port_type); ServiceEndpoint sep = new ServiceEndpoint(contract); sep.Binding = binding; WsdlContractConversionContext contract_context = new WsdlContractConversionContext(contract, port_type); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext( contract_context, sep, wsdlPort, wsb); foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.ImportEndpoint(this, endpoint_context); } return(sep); }
internal WsdlEndpointConversionContext(WsdlContractConversionContext contractContext, ServiceEndpoint endpoint, Binding wsdlBinding, Port wsdlport) { this.endpoint = endpoint; this.wsdlBinding = wsdlBinding; this.wsdlPort = wsdlport; this.contractContext = contractContext; this.wsdlOperationBindings = new Dictionary <OperationDescription, OperationBinding>(); this.operationDescriptionBindings = new Dictionary <OperationBinding, OperationDescription>(); this.wsdlMessageBindings = new Dictionary <MessageDescription, MessageBinding>(); this.messageDescriptionBindings = new Dictionary <MessageBinding, MessageDescription>(); this.wsdlFaultBindings = new Dictionary <FaultDescription, FaultBinding>(); this.faultDescriptionBindings = new Dictionary <FaultBinding, FaultDescription>(); }
internal WsdlEndpointConversionContext(WsdlContractConversionContext contractContext, ServiceEndpoint endpoint, Binding wsdlBinding, Port wsdlport) { this.endpoint = endpoint; this.wsdlBinding = wsdlBinding; this.wsdlPort = wsdlport; this.contractContext = contractContext; this.wsdlOperationBindings = new Dictionary<OperationDescription, OperationBinding>(); this.operationDescriptionBindings = new Dictionary<OperationBinding, OperationDescription>(); this.wsdlMessageBindings = new Dictionary<MessageDescription, MessageBinding>(); this.messageDescriptionBindings = new Dictionary<MessageBinding, MessageDescription>(); this.wsdlFaultBindings = new Dictionary<FaultDescription, FaultBinding>(); this.faultDescriptionBindings = new Dictionary<FaultBinding, FaultDescription>(); }
/// <summary>Called when importing a contract.</summary> /// <param name="importer">The importer.</param> /// <param name="context">The import context to be modified.</param> public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { // Ensure that the client class has been appropriately created in order for us to add methods to it. context.Contract.Behaviors.Add(new TaskAsyncServiceContractGenerationExtension()); // For each operation, add a task-based async equivalent. foreach (Operation operation in context.WsdlPortType.Operations) { var description = context.Contract.Operations.Find(operation.Name); if (description != null) description.Behaviors.Add(new TaskAsyncOperationContractGenerationExtension()); } }
internal WsdlEndpointConversionContext(WsdlEndpointConversionContext bindingContext, ServiceEndpoint endpoint, Port wsdlport) { this.endpoint = endpoint; this.wsdlBinding = bindingContext.WsdlBinding; this.wsdlPort = wsdlport; this.contractContext = bindingContext.contractContext; this.wsdlOperationBindings = bindingContext.wsdlOperationBindings; this.operationDescriptionBindings = bindingContext.operationDescriptionBindings; this.wsdlMessageBindings = bindingContext.wsdlMessageBindings; this.messageDescriptionBindings = bindingContext.messageDescriptionBindings; this.wsdlFaultBindings = bindingContext.wsdlFaultBindings; this.faultDescriptionBindings = bindingContext.faultDescriptionBindings; }
internal WsdlEndpointConversionContext(WsdlEndpointConversionContext bindingContext, ServiceEndpoint endpoint, WsdlNS.Port wsdlport) { _endpoint = endpoint; _wsdlBinding = bindingContext.WsdlBinding; _wsdlPort = wsdlport; _contractContext = bindingContext._contractContext; _wsdlOperationBindings = bindingContext._wsdlOperationBindings; _operationDescriptionBindings = bindingContext._operationDescriptionBindings; _wsdlMessageBindings = bindingContext._wsdlMessageBindings; _messageDescriptionBindings = bindingContext._messageDescriptionBindings; _wsdlFaultBindings = bindingContext._wsdlFaultBindings; _faultDescriptionBindings = bindingContext._faultDescriptionBindings; }
internal WsdlEndpointConversionContext(WsdlContractConversionContext contractContext, ServiceEndpoint endpoint, WsdlNS.Binding wsdlBinding, WsdlNS.Port wsdlport) { _endpoint = endpoint; _wsdlBinding = wsdlBinding; _wsdlPort = wsdlport; _contractContext = contractContext; _wsdlOperationBindings = new Dictionary <OperationDescription, WsdlNS.OperationBinding>(); _operationDescriptionBindings = new Dictionary <WsdlNS.OperationBinding, OperationDescription>(); _wsdlMessageBindings = new Dictionary <MessageDescription, WsdlNS.MessageBinding>(); _messageDescriptionBindings = new Dictionary <WsdlNS.MessageBinding, MessageDescription>(); _wsdlFaultBindings = new Dictionary <FaultDescription, WsdlNS.FaultBinding>(); _faultDescriptionBindings = new Dictionary <WsdlNS.FaultBinding, FaultDescription>(); }
void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { string documentation = GetDocumentation(context.WsdlPortType); context.Contract.Behaviors.Add(new XmlCommentsSvcExtension(this, documentation)); foreach (Operation operation in context.WsdlPortType.Operations) { documentation = GetDocumentation(operation); if (!String.IsNullOrEmpty(documentation)) { OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name); operationDescription.Behaviors.Add(new XmlCommentsOpExtension(this, documentation)); } } }
private void CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension) { try { extension.ExportContract(this, contractContext); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.ThrowExtensionException(contractContext.Contract, extension, exception)); } }
void ImportEndpoint(Port port, WSBinding wsb, ServiceEndpoint sep, bool throwOnError) { BeforeImport(); var port_type = GetPortTypeFromBinding(wsb); var contract_context = new WsdlContractConversionContext(sep.Contract, port_type); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext( contract_context, sep, port, wsb); foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.ImportEndpoint(this, endpoint_context); } }
ServiceEndpoint ImportBinding(WSBinding binding, bool throwOnError) { if (bindingHash.ContainsKey(binding)) { var sep = bindingHash [binding]; if (sep != null) { return(sep); } if (!throwOnError) { return(null); } throw new InvalidOperationException(String.Format( "Failed to import binding {0}, an error has " + "already been reported before.", binding.Name)); } try { var port_type = GetPortTypeFromBinding(binding); var contract = ImportContract(port_type); var contract_context = new WsdlContractConversionContext(contract, port_type); var sep = ImportBinding(binding, contract_context); bindingHash.Add(binding, sep); return(sep); } catch (MetadataImportException) { bindingHash.Add(binding, null); if (throwOnError) { throw; } return(null); } catch (Exception ex) { bindingHash.Add(binding, null); var error = AddError( "Failed to import binding `{0}': {1}", binding.Name, ex.Message); if (throwOnError) { throw new MetadataImportException(error, ex); } return(null); } }
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; } } }
static void ImportFaultSoapAction(WsdlContractConversionContext contractContext, FaultDescription fault, FaultBinding wsdlFaultBinding) { string soapAction = SoapHelper.ReadSoapAction(wsdlFaultBinding.OperationBinding); if (contractContext != null) { OperationFault wsdlOperationFault = contractContext.GetOperationFault(fault); string wsaAction = WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(wsdlOperationFault); if (wsaAction == null && soapAction != null) fault.Action = soapAction; // } else { // } }
public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { XsdDataContractExporter xsdInventoryExporter; object dataContractExporter; if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter)) { xsdInventoryExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas); exporter.State.Add(typeof(XsdDataContractExporter), xsdInventoryExporter); } else { xsdInventoryExporter = (XsdDataContractExporter)dataContractExporter; } if (xsdInventoryExporter.Options == null) { xsdInventoryExporter.Options = new ExportOptions(); } xsdInventoryExporter.Options.DataContractSurrogate = this.surrogate; }
public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { if (importer == null) { throw new ArgumentNullException("importer"); } if (context == null) { throw new ArgumentNullException("context"); } if (this.importer != null || this.context != null) { throw new SystemException("INTERNAL ERROR: unexpected recursion of ImportContract method call"); } schema_set_in_use = new XmlSchemaSet(); schema_set_in_use.Add(importer.XmlSchemas); foreach (WSDL wsdl in importer.WsdlDocuments) { foreach (XmlSchema xs in wsdl.Types.Schemas) { schema_set_in_use.Add(xs); } } schema_set_in_use.Compile(); this.importer = importer; this.context = context; try { DoImportContract(); } finally { this.importer = null; this.context = null; } }
void IWsdlImportExtension.ImportContract (WsdlImporter importer, WsdlContractConversionContext context) { if (!enabled) return; if (importer == null) throw new ArgumentNullException ("importer"); if (context == null) throw new ArgumentNullException ("context"); if (this.importer != null || this.context != null) throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call"); this.importer = importer; this.context = context; try { DoImportContract (); } finally { this.importer = null; this.context = null; } }
public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { if (exporter == null) throw new ArgumentNullException("exporter"); 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(); if (xsdDCExporter.Options.DataContractSurrogate == null) xsdDCExporter.Options.DataContractSurrogate = new AllowNonSerializableTypesSurrogate(); }
public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { // Contract Documentation if (context.WsdlPortType.Documentation != null) { // System examines the contract behaviors to see whether any implement IWsdlImportExtension. context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.Documentation)); } // Operation Documentation foreach (Operation operation in context.WsdlPortType.Operations) { if (operation.Documentation != null) { OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name); if (operationDescription != null) { // System examines the operation behaviors to see whether any implement IWsdlImportExtension. operationDescription.Behaviors.Add(new WsdlDocumentationImporter(operation.Documentation)); } } } }
ContractDescription DoImportContract(PortType wsdlPortType) { BeforeImport(); ContractDescription cd = new ContractDescription(wsdlPortType.Name, wsdlPortType.ServiceDescription.TargetNamespace); foreach (Operation op in wsdlPortType.Operations) { OperationDescription op_descr = new OperationDescription(op.Name, cd); foreach (OperationMessage opmsg in op.Messages) { /* OperationMessageCollection */ MessageDescription msg_descr; MessageDirection dir = MessageDirection.Input; string action = ""; if (opmsg.GetType() == typeof(OperationInput)) { dir = MessageDirection.Input; } else if (opmsg.GetType() == typeof(OperationOutput)) { dir = MessageDirection.Output; } /* FIXME: OperationFault--> OperationDescription.Faults ? */ if (opmsg.ExtensibleAttributes != null) { for (int i = 0; i < opmsg.ExtensibleAttributes.Length; i++) { if (opmsg.ExtensibleAttributes [i].LocalName == "Action" && opmsg.ExtensibleAttributes [i].NamespaceURI == "http://www.w3.org/2006/05/addressing/wsdl") { /* addressing:Action */ action = opmsg.ExtensibleAttributes [i].Value; } /* FIXME: other attributes ? */ } } // fill Action from operation binding if required. if (action == "") { if (dir != MessageDirection.Input) { action = GetActionFromOperationBinding(wsdlPortType, op.Name); } else { action = "*"; } } msg_descr = new MessageDescription(action, dir); /* FIXME: Headers ? */ op_descr.Messages.Add(msg_descr); } cd.Operations.Add(op_descr); } WsdlContractConversionContext context = new WsdlContractConversionContext(cd, wsdlPortType); foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.ImportContract(this, context); } return(cd); }
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); } } } } }
void ExportEndpoint(ServiceEndpoint endpoint, bool rejectDuplicate) { List <IWsdlExportExtension> extensions = ExportContractInternal(endpoint.Contract, rejectDuplicate); //FIXME: Namespace WSServiceDescription sd = GetServiceDescription("http://tempuri.org/"); if (sd.TargetNamespace != endpoint.Contract.Namespace) { sd.Namespaces.Add("i0", endpoint.Contract.Namespace); //Import Import import = new Import(); import.Namespace = endpoint.Contract.Namespace; sd.Imports.Add(import); } if (endpoint.Binding == null) { throw new ArgumentException(String.Format( "Binding for ServiceEndpoint named '{0}' is null", endpoint.Name)); } bool msg_version_none = endpoint.Binding.MessageVersion != null && endpoint.Binding.MessageVersion.Equals(MessageVersion.None); //ExportBinding WSBinding ws_binding = new WSBinding(); //<binding name = .. ws_binding.Name = String.Concat(endpoint.Binding.Name, "_", endpoint.Contract.Name); //<binding type = .. ws_binding.Type = new QName(endpoint.Contract.Name, endpoint.Contract.Namespace); sd.Bindings.Add(ws_binding); if (!msg_version_none) { SoapBinding soap_binding = new SoapBinding(); soap_binding.Transport = SoapBinding.HttpTransport; soap_binding.Style = SoapBindingStyle.Document; ws_binding.Extensions.Add(soap_binding); } // <operation foreach (OperationDescription sm_op in endpoint.Contract.Operations) { OperationBinding op_binding = new OperationBinding(); op_binding.Name = sm_op.Name; //FIXME: Move to IWsdlExportExtension .. ? foreach (MessageDescription sm_md in sm_op.Messages) { if (sm_md.Direction == MessageDirection.Input) { //<input InputBinding in_binding = new InputBinding(); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding(); soap_body_binding.Use = SoapBindingUse.Literal; in_binding.Extensions.Add(soap_body_binding); //Set Action //<operation > <soap:operation soapAction .. > SoapOperationBinding soap_operation_binding = new SoapOperationBinding(); soap_operation_binding.SoapAction = sm_md.Action; soap_operation_binding.Style = SoapBindingStyle.Document; op_binding.Extensions.Add(soap_operation_binding); } op_binding.Input = in_binding; } else { //<output OutputBinding out_binding = new OutputBinding(); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding(); soap_body_binding.Use = SoapBindingUse.Literal; out_binding.Extensions.Add(soap_body_binding); } op_binding.Output = out_binding; } } ws_binding.Operations.Add(op_binding); } //Add <service Port ws_port = ExportService(sd, ws_binding, endpoint.Address, msg_version_none); //Call IWsdlExportExtension.ExportEndpoint WsdlContractConversionContext contract_context = new WsdlContractConversionContext( endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext( contract_context, endpoint, ws_port, ws_binding); if (extensions != null) { foreach (IWsdlExportExtension extn in extensions) { extn.ExportEndpoint(this, endpoint_context); } } }
void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext) { if (exporter == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter"); if (contractContext == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractContext"); new DataContractSerializerMessageContractExporter(exporter, contractContext, this.operation, this).ExportMessageContract(); }
internal DataContractSerializerMessageContractExporter(WsdlExporter exporter, WsdlContractConversionContext context, OperationDescription operation, IOperationBehavior extension) : base(exporter, context, operation, extension) { }
void System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext) { }
void IWsdlExportExtension.ExportContract( WsdlExporter exporter, WsdlContractConversionContext context) { throw new NotImplementedException(); }
EndpointExportMap ExportEndpoint_Internal (ServiceEndpoint endpoint) { var map = ExportedEndpoints.FirstOrDefault (m => m.Endpoint == endpoint); if (map != null) return map; int index = 0; var baseName = String.Concat (endpoint.Binding.Name, "_", endpoint.Contract.Name); var name = baseName; while (ExportedEndpoints.Exists (m => m.Name == name)) name = String.Concat (baseName, (++index).ToString ()); map = new EndpointExportMap (name, endpoint); ExportedEndpoints.Add (map); var contract = ExportContractInternal (endpoint.Contract); //FIXME: Namespace WSServiceDescription sd = GetServiceDescription ("http://tempuri.org/"); if (sd.TargetNamespace != endpoint.Contract.Namespace) { sd.Namespaces.Add ("i0", endpoint.Contract.Namespace); //Import Import import = new Import (); import.Namespace = endpoint.Contract.Namespace; sd.Imports.Add (import); } if (endpoint.Binding == null) throw new ArgumentException (String.Format ( "Binding for ServiceEndpoint named '{0}' is null", endpoint.Name)); var extensions = new List<IWsdlExportExtension> (); var extensionTypes = new Dictionary<Type, IWsdlExportExtension> (); if (contract.Results != null) { foreach (var extension in contract.Results) { var type = extension.GetType (); if (extensionTypes.ContainsKey (type)) continue; extensionTypes.Add (type, extension); extensions.Add (extension); } } var bindingElements = endpoint.Binding.CreateBindingElements (); foreach (var element in bindingElements) { var extension = element as IWsdlExportExtension; if (extension == null) continue; var type = extension.GetType (); if (extensionTypes.ContainsKey (type)) continue; extensionTypes.Add (type, extension); extensions.Add (extension); } //ExportBinding WSBinding ws_binding = new WSBinding (); //<binding name = .. ws_binding.Name = name; //<binding type = .. ws_binding.Type = new QName (endpoint.Contract.Name, endpoint.Contract.Namespace); sd.Bindings.Add (ws_binding); // <operation foreach (OperationDescription sm_op in endpoint.Contract.Operations) { var op_binding = CreateOperationBinding (endpoint, sm_op); ws_binding.Operations.Add (op_binding); } //Add <service Port ws_port = ExportService (sd, ws_binding, endpoint.Address); //Call IWsdlExportExtension.ExportEndpoint WsdlContractConversionContext contract_context = new WsdlContractConversionContext ( endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext ( contract_context, endpoint, ws_port, ws_binding); foreach (var extension in extensions) { try { extension.ExportEndpoint (this, endpoint_context); } catch (Exception ex) { var error = AddError ( "Failed to export endpoint '{0}': wsdl exporter '{1}' " + "threw an exception: {2}", endpoint.Name, extension.GetType (), ex); throw new MetadataExportException (error, ex); } } try { ExportPolicy (endpoint, ws_binding); } catch (MetadataExportException) { throw; } catch (Exception ex) { var error = AddError ( "Failed to export endpoint '{0}': unhandled exception " + "while exporting policy: {1}", endpoint.Name, ex); throw new MetadataExportException (error, ex); } return map; }
//IWsdlExportExtension void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { }
//IWsdlExportExtension void IWsdlExportExtension.ExportContract (WsdlExporter exporter, WsdlContractConversionContext context) { }
void IWsdlImportExtension.ImportContract (WsdlImporter importer, WsdlContractConversionContext context) { }
ContractExportMap ExportContractInternal(ContractDescription contract) { if (ExportedContracts.ContainsKey(contract)) { return(ExportedContracts [contract]); } QName qname = new QName(contract.Name, contract.Namespace); if (ExportedContracts.Any(m => m.Value.QName == qname)) { throw new ArgumentException(String.Format( "A ContractDescription with Namespace : {0} and Name : {1} has already been exported.", contract.Namespace, contract.Name)); } WSServiceDescription sd = GetServiceDescription(contract.Namespace); List <IWsdlExportExtension> extensions = new List <IWsdlExportExtension> (); foreach (IWsdlExportExtension extn in contract.Behaviors.FindAll <IWsdlExportExtension> ()) { extensions.Add(extn); } XmlDocument xdoc = new XmlDocument(); PortType ws_port = new PortType(); ws_port.Name = contract.Name; foreach (OperationDescription sm_op in contract.Operations) { Operation ws_op = new Operation(); ws_op.Name = sm_op.Name; foreach (MessageDescription sm_md in sm_op.Messages) { //OperationMessage OperationMessage ws_opmsg; WSMessage ws_msg = new WSMessage(); MessagePart ws_msgpart; if (sm_md.Direction == MessageDirection.Input) { ws_opmsg = new OperationInput(); ws_msg.Name = String.Concat(ws_port.Name, "_", ws_op.Name, "_", "InputMessage"); ws_msgpart = ExportMessageBodyDescription(sm_md.Body, ws_op.Name, sd.TargetNamespace); } else { ws_opmsg = new OperationOutput(); ws_msg.Name = String.Concat(ws_port.Name, "_", ws_op.Name, "_", "OutputMessage"); ws_msgpart = ExportMessageBodyDescription(sm_md.Body, ws_op.Name + "Response", sd.TargetNamespace); } ws_msg.Parts.Add(ws_msgpart); /* FIXME: Faults */ //Action XmlAttribute attr = xdoc.CreateAttribute("wsaw", "Action", "http://www.w3.org/2006/05/addressing/wsdl"); attr.Value = sm_md.Action; ws_opmsg.ExtensibleAttributes = new XmlAttribute [] { attr }; //FIXME: Set .Input & .Output ws_opmsg.Message = new QName(ws_msg.Name, sd.TargetNamespace); ws_op.Messages.Add(ws_opmsg); sd.Messages.Add(ws_msg); } ws_port.Operations.Add(ws_op); foreach (IWsdlExportExtension extn in sm_op.Behaviors.FindAll <IWsdlExportExtension> ()) { extensions.Add(extn); } } //Add Imports for <types XmlSchema xs_import = new XmlSchema(); xs_import.TargetNamespace = String.Concat( contract.Namespace, contract.Namespace.EndsWith("/") ? "" : "/", "Imports"); foreach (XmlSchema schema in GeneratedXmlSchemas.Schemas()) { XmlSchemaImport imp = new XmlSchemaImport(); imp.Namespace = schema.TargetNamespace; xs_import.Includes.Add(imp); } sd.Types.Schemas.Add(xs_import); sd.PortTypes.Add(ws_port); var map = new ContractExportMap(qname, contract, extensions); ExportedContracts.Add(contract, map); WsdlContractConversionContext context = new WsdlContractConversionContext(contract, ws_port); foreach (IWsdlExportExtension extn in extensions) { extn.ExportContract(this, context); } return(map); }
public override void ExportEndpoint (ServiceEndpoint endpoint) { List<IWsdlExportExtension> extensions = ExportContractInternal (endpoint.Contract); //FIXME: Namespace WSServiceDescription sd = GetServiceDescription ("http://tempuri.org/"); if (sd.TargetNamespace != endpoint.Contract.Namespace) { sd.Namespaces.Add ("i0", endpoint.Contract.Namespace); //Import Import import = new Import (); import.Namespace = endpoint.Contract.Namespace; sd.Imports.Add (import); } if (endpoint.Binding == null) throw new ArgumentException (String.Format ( "Binding for ServiceEndpoint named '{0}' is null", endpoint.Name)); bool msg_version_none = endpoint.Binding.MessageVersion != null && endpoint.Binding.MessageVersion.Equals (MessageVersion.None); //ExportBinding WSBinding ws_binding = new WSBinding (); //<binding name = .. ws_binding.Name = String.Concat (endpoint.Binding.Name, "_", endpoint.Contract.Name); //<binding type = .. ws_binding.Type = new QName (endpoint.Contract.Name, endpoint.Contract.Namespace); sd.Bindings.Add (ws_binding); if (!msg_version_none) { SoapBinding soap_binding = new SoapBinding (); soap_binding.Transport = SoapBinding.HttpTransport; soap_binding.Style = SoapBindingStyle.Document; ws_binding.Extensions.Add (soap_binding); } // <operation foreach (OperationDescription sm_op in endpoint.Contract.Operations){ OperationBinding op_binding = new OperationBinding (); op_binding.Name = sm_op.Name; //FIXME: Move to IWsdlExportExtension .. ? foreach (MessageDescription sm_md in sm_op.Messages) { if (sm_md.Direction == MessageDirection.Input) { //<input InputBinding in_binding = new InputBinding (); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding (); soap_body_binding.Use = SoapBindingUse.Literal; in_binding.Extensions.Add (soap_body_binding); //Set Action //<operation > <soap:operation soapAction .. > SoapOperationBinding soap_operation_binding = new SoapOperationBinding (); soap_operation_binding.SoapAction = sm_md.Action; soap_operation_binding.Style = SoapBindingStyle.Document; op_binding.Extensions.Add (soap_operation_binding); } op_binding.Input = in_binding; } else { //<output OutputBinding out_binding = new OutputBinding (); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding (); soap_body_binding.Use = SoapBindingUse.Literal; out_binding.Extensions.Add (soap_body_binding); } op_binding.Output = out_binding; } } ws_binding.Operations.Add (op_binding); } //Add <service Port ws_port = ExportService (sd, ws_binding, endpoint.Address, msg_version_none); //Call IWsdlExportExtension.ExportEndpoint WsdlContractConversionContext contract_context = new WsdlContractConversionContext ( endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext ( contract_context, endpoint, ws_port, ws_binding); foreach (IWsdlExportExtension extn in extensions) extn.ExportEndpoint (this, endpoint_context); }
public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { }
List<IWsdlExportExtension> ExportContractInternal (ContractDescription contract) { QName qname = new QName (contract.Name, contract.Namespace); if (ExportedContracts.ContainsKey (qname)) throw new ArgumentException (String.Format ( "A ContractDescription with Namespace : {0} and Name : {1} has already been exported.", contract.Namespace, contract.Name)); WSServiceDescription sd = GetServiceDescription (contract.Namespace); List<IWsdlExportExtension> extensions = new List<IWsdlExportExtension> (); foreach (IWsdlExportExtension extn in contract.Behaviors.FindAll<IWsdlExportExtension> ()) extensions.Add (extn); XmlDocument xdoc = new XmlDocument (); PortType ws_port = new PortType (); ws_port.Name = contract.Name; foreach (OperationDescription sm_op in contract.Operations) { Operation ws_op = new Operation (); ws_op.Name = sm_op.Name; foreach (MessageDescription sm_md in sm_op.Messages) { //OperationMessage OperationMessage ws_opmsg; WSMessage ws_msg = new WSMessage (); MessagePart ws_msgpart; if (sm_md.Direction == MessageDirection.Input) { ws_opmsg = new OperationInput (); ws_msg.Name = String.Concat (ws_port.Name, "_", ws_op.Name, "_", "InputMessage"); ws_msgpart = ExportMessageBodyDescription (sm_md.Body, ws_op.Name, sd.TargetNamespace); } else { ws_opmsg = new OperationOutput (); ws_msg.Name = String.Concat (ws_port.Name, "_", ws_op.Name, "_", "OutputMessage"); ws_msgpart = ExportMessageBodyDescription (sm_md.Body, ws_op.Name + "Response", sd.TargetNamespace); } ws_msg.Parts.Add (ws_msgpart); /* FIXME: Faults */ //Action XmlAttribute attr = xdoc.CreateAttribute ("wsaw", "Action", "http://www.w3.org/2006/05/addressing/wsdl"); attr.Value = sm_md.Action; ws_opmsg.ExtensibleAttributes = new XmlAttribute [] { attr }; //FIXME: Set .Input & .Output ws_opmsg.Message = new QName (ws_msg.Name, sd.TargetNamespace); ws_op.Messages.Add (ws_opmsg); sd.Messages.Add (ws_msg); } ws_port.Operations.Add (ws_op); foreach (IWsdlExportExtension extn in sm_op.Behaviors.FindAll<IWsdlExportExtension> ()) extensions.Add (extn); } //Add Imports for <types XmlSchema xs_import = new XmlSchema (); xs_import.TargetNamespace = String.Concat ( contract.Namespace, contract.Namespace.EndsWith ("/") ? "" : "/", "Imports"); foreach (XmlSchema schema in GeneratedXmlSchemas.Schemas ()) { XmlSchemaImport imp = new XmlSchemaImport (); imp.Namespace = schema.TargetNamespace; xs_import.Includes.Add (imp); } sd.Types.Schemas.Add (xs_import); sd.PortTypes.Add (ws_port); ExportedContracts [qname] = contract; WsdlContractConversionContext context = new WsdlContractConversionContext (contract, ws_port); foreach (IWsdlExportExtension extn in extensions) extn.ExportContract (this, context); return extensions; }
void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context) { }
void IWsdlExportExtension.ExportContract ( WsdlExporter exporter, WsdlContractConversionContext context) { throw new NotImplementedException (); }
EndpointExportMap ExportEndpoint_Internal(ServiceEndpoint endpoint) { var map = ExportedEndpoints.FirstOrDefault(m => m.Endpoint == endpoint); if (map != null) { return(map); } int index = 0; var baseName = String.Concat(endpoint.Binding.Name, "_", endpoint.Contract.Name); var name = baseName; while (ExportedEndpoints.Exists(m => m.Name == name)) { name = String.Concat(baseName, (++index).ToString()); } map = new EndpointExportMap(name, endpoint); ExportedEndpoints.Add(map); var contract = ExportContractInternal(endpoint.Contract); //FIXME: Namespace WSServiceDescription sd = GetServiceDescription("http://tempuri.org/"); if (sd.TargetNamespace != endpoint.Contract.Namespace) { sd.Namespaces.Add("i0", endpoint.Contract.Namespace); //Import Import import = new Import(); import.Namespace = endpoint.Contract.Namespace; sd.Imports.Add(import); } if (endpoint.Binding == null) { throw new ArgumentException(String.Format( "Binding for ServiceEndpoint named '{0}' is null", endpoint.Name)); } var extensions = new List <IWsdlExportExtension> (); var extensionTypes = new Dictionary <Type, IWsdlExportExtension> (); if (contract.Results != null) { foreach (var extension in contract.Results) { var type = extension.GetType(); if (extensionTypes.ContainsKey(type)) { continue; } extensionTypes.Add(type, extension); extensions.Add(extension); } } var bindingElements = endpoint.Binding.CreateBindingElements(); foreach (var element in bindingElements) { var extension = element as IWsdlExportExtension; if (extension == null) { continue; } var type = extension.GetType(); if (extensionTypes.ContainsKey(type)) { continue; } extensionTypes.Add(type, extension); extensions.Add(extension); } //ExportBinding WSBinding ws_binding = new WSBinding(); //<binding name = .. ws_binding.Name = name; //<binding type = .. ws_binding.Type = new QName(endpoint.Contract.Name, endpoint.Contract.Namespace); sd.Bindings.Add(ws_binding); // <operation foreach (OperationDescription sm_op in endpoint.Contract.Operations) { var op_binding = CreateOperationBinding(endpoint, sm_op); ws_binding.Operations.Add(op_binding); } //Add <service Port ws_port = ExportService(sd, ws_binding, endpoint.Address); //Call IWsdlExportExtension.ExportEndpoint WsdlContractConversionContext contract_context = new WsdlContractConversionContext( endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext( contract_context, endpoint, ws_port, ws_binding); foreach (var extension in extensions) { try { extension.ExportEndpoint(this, endpoint_context); } catch (Exception ex) { var error = AddError( "Failed to export endpoint '{0}': wsdl exporter '{1}' " + "threw an exception: {2}", endpoint.Name, extension.GetType(), ex); throw new MetadataExportException(error, ex); } } try { ExportPolicy(endpoint, ws_binding); } catch (MetadataExportException) { throw; } catch (Exception ex) { var error = AddError( "Failed to export endpoint '{0}': unhandled exception " + "while exporting policy: {1}", endpoint.Name, ex); throw new MetadataExportException(error, ex); } return(map); }