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); }
Port ExportService(WSServiceDescription sd, WSBinding ws_binding, EndpointAddress address, bool msg_version_none) { if (address == null) { return(null); } Service ws_svc = GetService(sd, "service"); sd.Name = "service"; Port ws_port = new Port(); ws_port.Name = ws_binding.Name; ws_port.Binding = new QName(ws_binding.Name, sd.TargetNamespace); if (!msg_version_none) { SoapAddressBinding soap_addr = new SoapAddressBinding(); soap_addr.Location = address.Uri.AbsoluteUri; ws_port.Extensions.Add(soap_addr); } ws_svc.Ports.Add(ws_port); return(ws_port); }
public SMBinding ImportBinding(WSBinding binding) { /* Default, CustomBinding.. */ CustomBinding smbinding = new CustomBinding(); foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.BeforeImport(wsdl_documents, xmlschemas, policies); } smbinding.Name = binding.Name; smbinding.Namespace = binding.ServiceDescription.TargetNamespace; //FIXME: Added by MessageEncodingBindingElementConverter.ImportPolicy smbinding.Elements.Add(new TextMessageEncodingBindingElement()); /*ImportContract * PortType portType = null; * foreach (WSServiceDescription sd in wsdl_documents) { * portType = sd.PortTypes [binding.Type.Name]; * if (portType != null) * break; * } * * //FIXME: if portType == null */ // FIXME: ImportContract here.. return(smbinding); }
static Type GetServiceType(Binding soapBinding, Assembly assembly) { foreach (var type in assembly.GetTypes()) { var bindingAttribute = type.GetCustomAttributes(typeof (WebServiceBindingAttribute), false) .Cast<WebServiceBindingAttribute>().SingleOrDefault(); if (bindingAttribute != null && bindingAttribute.Name == soapBinding.Name) return type; } return null; //var serviceTypes = new List<Type>(); //// FIXME: Best way to match the service/binding to the implementing type //// //foreach (var type in assembly.GetTypes()) //{ // var bindingAttributes = type.GetCustomAttributes(typeof (WebServiceBindingAttribute), false); // if (bindingAttributes.Length != 0) serviceTypes.Add(type); //} //var name = soapBinding.Type.Name; //return string.IsNullOrEmpty(name) // ? new Type[0] // : serviceTypes.Where(t => t.Name == name || t.Name.EndsWith(name)); }
internal static WS.Soap12Binding GetTcpSoapBinding(WS.Binding binding) { WS.Soap12Binding soap = null; foreach (var extension in binding.Extensions) { var check = extension as WS.Soap12Binding; if (check != null) { soap = check; break; } } if (soap == null) { return(null); } if (soap.Transport != TcpTransport) { return(null); } if (soap.Style != WS.SoapBindingStyle.Document) { return(null); } return(soap); }
public CustomPolicyConversionContext(WS.Binding binding, ServiceEndpoint endpoint) : base(endpoint) { this.binding = binding; assertions = new PolicyAssertionCollection(); binding_elements = ((CustomBinding)endpoint.Binding).Elements; }
internal WsdlEndpointConversionContext(WsdlContractConversionContext context, ServiceEndpoint endpoint, Port port, WSBinding wsdlBinding) { this.context = context; this.endpoint = endpoint; this.port = port; this.wsdl_binding = wsdlBinding; }
public ServiceEndpointCollection ImportEndpoints(WSBinding binding) { var coll = new ServiceEndpointCollection(); ImportEndpoints(coll, binding); return(coll); }
public CustomPolicyConversionContext (WS.Binding binding, ServiceEndpoint endpoint) : base (endpoint) { this.binding = binding; assertions = new PolicyAssertionCollection (); binding_elements = ((CustomBinding)endpoint.Binding).Elements; }
internal WsdlEndpointConversionContext (WsdlContractConversionContext context, ServiceEndpoint endpoint, Port port, WSBinding wsdlBinding) { this.context = context; this.endpoint = endpoint; this.port = port; this.wsdl_binding = wsdlBinding; }
//DONE //This method generates a list of operations from a web service description. Returns a list of the //webservice's operations on success, and null on failure. public string[] GetListOfOperations(string webServiceURL) { List<string> ListOfOperations = new List<string>(); WebClient webServiceClient = new WebClient(); Binding binding = new Binding(); try { Stream serviceStream = webServiceClient.OpenRead(webServiceURL + "?wsdl"); //This gets the WSDL file... ServiceDescription webServiceDescription = ServiceDescription.Read(serviceStream); //Get a list of operations from the web service description... binding = webServiceDescription.Bindings[0]; OperationBindingCollection operationCollection = binding.Operations; foreach (OperationBinding operation in operationCollection) { ListOfOperations.Add(operation.Name); } } catch (Exception ex) { throw ex; } return ListOfOperations.ToArray(); }
static List<ExplorerItem> BuildEntities(Type serviceType, Binding soapBinding) { var list = new List<ExplorerItem>(); foreach (var operation in GetSoapOperations(soapBinding)) list.Add(CreateExplorerOperation(serviceType, operation)); return list; }
public void Parse() { foreach (Service service in _services[0].Services ) { TreeNode tnService=new TreeNode(service.Name) ; tnService.ImageIndex=1; tnService.SelectedImageIndex=1; foreach (Port port in service.Ports) { XmlQualifiedName bindName=port.Binding ; Binding bind=_services.GetBinding(bindName); PortType portType=_services.GetPortType(bind.Type) ; TreeNode tnPort=new TreeNode (port.Name); tnPort.ImageIndex=6; tnPort.SelectedImageIndex=6; string protocol=GetProtocol (bind); string portDesc="Protocol: " + protocol + "\n"; switch (protocol) { case "Soap": { SoapAddressBinding ad=(SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding)); portDesc += "Location: " + ad.Location + "\n"; break; } case "HttpGet": { HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding)); portDesc += "Location: " + ad.Location + "\n"; break; case "HttpPost": { HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding)); portDesc += "Location: " + ad.Location + "\n"; break; } } tnPort.Tag=portDesc; foreach (OperationBinding obin in bind.Operations) { foreach (Operation oper in portType.Operations) if (obin.Name.Equals(oper.Name) ) { TreeNode tnOper=TranslateOperation (port, obin, oper, protocol); tnOper.ImageIndex=11; tnOper.SelectedImageIndex=11; if (tnOper != null) { tnPort.Nodes.Add (tnOper); }; } } tnPort.Expand (); tnService.Nodes.Add(tnPort) ; } ServiceNode.Nodes.Add (tnService); } }
private string GetProtocol (Binding binding) { if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap"; HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding)); if (hb == null) return ""; if (hb.Verb == "POST") return "HttpPost"; if (hb.Verb == "GET") return "HttpGet"; return ""; }
WSBinding GetBinding(WSServiceDescription sd, string name, string label) { WSBinding ret = sd.Bindings [name]; if (ret == null) { Assert.Fail(String.Format("[{0}] Binding named '{1}' not found.", label, name)); } return(ret); }
private void ConvertBinding(DescriptionType wsdl2, ServiceDescription wsdl1) { var bindings = wsdl2.Items.Where(s => s is BindingType); foreach (BindingType b2 in bindings) { var b1 = new Binding(); wsdl1.Bindings.Add(b1); b1.Name = b2.name; b1.Type = b2.@interface; var v = GetSoapVersion(b2); if (v == SoapVersion.Soap11) { b1.Extensions.Add(new SoapBinding { Transport = "http://schemas.xmlsoap.org/soap/http" }); } else { b1.Extensions.Add(new Soap12Binding { Transport = "http://schemas.xmlsoap.org/soap/http" }); } var operations = b2.Items.Where(s => s is BindingOperationType); foreach (BindingOperationType op2 in operations) { var op1 = new OperationBinding(); b1.Operations.Add(op1); op1.Name = [email protected]; var soap = v == SoapVersion.Soap11 ? new SoapOperationBinding() : new Soap12OperationBinding(); op1.Extensions.Add(soap); soap.SoapAction = FindSoapAction(op2); soap.Style = SoapBindingStyle.Document; var body = v == SoapVersion.Soap11 ? new SoapBodyBinding() : new Soap12BodyBinding(); body.Use = SoapBindingUse.Literal; op1.Input = new InputBinding(); op1.Input.Extensions.Add(body); op1.Output = new OutputBinding(); op1.Output.Extensions.Add(body); HandleHeaders(wsdl1, op2, ItemsChoiceType1.input, op1.Input, v); HandleHeaders(wsdl1, op2, ItemsChoiceType1.output, op1.Output, v); } } }
internal static EnvelopeVersion GetSoapVersion(WsdlNS.Binding wsdlBinding) { foreach (object o in wsdlBinding.Extensions) { if (o is WsdlNS.SoapBinding) { return(o is WsdlNS.Soap12Binding ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11); } } return(EnvelopeVersion.Soap12); }
public void TestAddBinding () { const string bindingName = "testBinding"; Binding b = new Binding (); b.Name = bindingName; bc.Add (b); Assert.AreEqual (1, bc.Count); Assert.AreEqual (b, bc[bindingName]); }
OperationBinding FindOperation(Binding binding, string name) { foreach (OperationBinding oper in binding.Operations) { if (oper.Input.Name != null) { if (oper.Input.Name == name) return oper; } else if (oper.Name == name) return oper; } return null; }
private static void SetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter, EnvelopeVersion version) { object versions = null; if (!exporter.State.TryGetValue(SoapVersionStateKey, out versions)) { versions = new Dictionary <WsdlNS.Binding, EnvelopeVersion>(); exporter.State[SoapVersionStateKey] = versions; } ((Dictionary <WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding] = version; }
private static Type GetServiceType(Binding soapBinding, Assembly assembly) { foreach (var type in assembly.GetTypes()) { var bindingAttribute = type.GetCustomAttributes(typeof (WebServiceBindingAttribute), false) .Cast<WebServiceBindingAttribute>().SingleOrDefault(); if (bindingAttribute != null && bindingAttribute.Name == soapBinding.Name) return type; } return null; }
PolicyConversionContext ExportPolicy(ServiceEndpoint endpoint, WSBinding binding) { var context = new CustomPolicyConversionContext(endpoint); var elements = endpoint.Binding.CreateBindingElements(); foreach (var element in elements) { var exporter = element as IPolicyExportExtension; if (exporter == null) { continue; } try { exporter.ExportPolicy(this, context); } catch (Exception ex) { var error = AddError( "Failed to export endpoint '{0}': policy exporter " + "'{1}' threw an exception: {2}", endpoint.Name, element.GetType(), ex); throw new MetadataExportException(error, ex); } } var assertions = context.GetBindingAssertions(); if (assertions.Count == 0) { return(context); } var doc = new XmlDocument(); var policy = doc.CreateElement("wsp", "Policy", PolicyImportHelper.PolicyNS); doc.AppendChild(policy); var exactlyOne = doc.CreateElement("wsp", "ExactlyOne", PolicyImportHelper.PolicyNS); var all = doc.CreateElement("wsp", "All", PolicyImportHelper.PolicyNS); policy.AppendChild(exactlyOne); exactlyOne.AppendChild(all); foreach (var assertion in assertions) { var imported = doc.ImportNode(assertion, true); all.AppendChild(imported); } binding.Extensions.Add(policy); return(context); }
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); }
OperationBinding GetOperationBinding(WSBinding b, string name, string label) { foreach (OperationBinding op in b.Operations) { if (op.Name == name) { return(op); } } Assert.Fail(String.Format("[{0}] OperationBinding named '{1}' not found.", label, name)); return(null); }
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(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 static WsdlNS.SoapBindingStyle GetStyle(WsdlNS.Binding binding) { WsdlNS.SoapBindingStyle style = WsdlNS.SoapBindingStyle.Default; if (binding != null) { WsdlNS.SoapBinding soapBinding = binding.Extensions.Find(typeof(WsdlNS.SoapBinding)) as WsdlNS.SoapBinding; if (soapBinding != null) { style = soapBinding.Style; } } return(style); }
private static EnvelopeVersion GetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter) { object versions = null; if (exporter.State.TryGetValue(SoapVersionStateKey, out versions)) { if (versions != null && ((Dictionary <WsdlNS.Binding, EnvelopeVersion>)versions).ContainsKey(wsdlBinding)) { return(((Dictionary <WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding]); } } return(null); }
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>(); }
internal WsdlEndpointConversionContext(WsdlEndpointConversionContext bindingContext, ServiceEndpoint endpoint, WsdlNS.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; }
PortType GetPortTypeFromBinding(WSBinding binding) { foreach (WSServiceDescription sd in wsdl_documents) { var port_type = sd.PortTypes [binding.Type.Name]; if (port_type != null) { return(port_type); } } throw new MetadataImportException(AddError( "PortType named {0} not found in namespace {1}.", binding.Type.Name, binding.Type.Namespace)); }
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); } }
static bool ContainsHttpBindingExtension(WsdlNS.Binding wsdlBinding) { //avoiding using wsdlBinding.Extensions.Find(typeof(WsdlNS.HttpBinding)) so the extension won't be marked as handled foreach (object extension in wsdlBinding.Extensions) { if (extension is WsdlNS.HttpBinding) { string httpVerb = ((WsdlNS.HttpBinding)extension).Verb; if (httpVerb.Equals("GET", StringComparison.OrdinalIgnoreCase) || httpVerb.Equals("POST", StringComparison.OrdinalIgnoreCase)) { return(true); } } } return(false); }
void Add(ServiceDescription description) { TreeNode rootNode = new TreeNode(GetName(description)); rootNode.Tag = description; rootNode.ImageIndex = ServiceDescriptionImageIndex; rootNode.SelectedImageIndex = ServiceDescriptionImageIndex; webServicesTreeView.Nodes.Add(rootNode); foreach (Service service in description.Services) { // Add a Service node TreeNode serviceNode = new TreeNode(service.Name); serviceNode.Tag = service; serviceNode.ImageIndex = ServiceImageIndex; serviceNode.SelectedImageIndex = ServiceImageIndex; rootNode.Nodes.Add(serviceNode); foreach (Port port in service.Ports) { TreeNode portNode = new TreeNode(port.Name); portNode.Tag = port; portNode.ImageIndex = PortImageIndex; portNode.SelectedImageIndex = PortImageIndex; serviceNode.Nodes.Add(portNode); // Get the operations System.Web.Services.Description.Binding binding = description.Bindings[port.Binding.Name]; if (binding != null) { PortType portType = description.PortTypes[binding.Type.Name]; if (portType != null) { foreach (Operation operation in portType.Operations) { TreeNode operationNode = new TreeNode(operation.Name); operationNode.Tag = operation; operationNode.ImageIndex = OperationImageIndex; operationNode.SelectedImageIndex = OperationImageIndex; portNode.Nodes.Add(operationNode); } } } } } webServicesTreeView.ExpandAll(); }
// static WsdlNS.SoapBinding CreateSoapBinding(EnvelopeVersion version, WsdlNS.Binding wsdlBinding) { WsdlNS.SoapBinding soapBinding = null; if (version == EnvelopeVersion.Soap12) { soapBinding = new WsdlNS.Soap12Binding(); } else if (version == EnvelopeVersion.Soap11) { soapBinding = new WsdlNS.SoapBinding(); } Fx.Assert(soapBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class"); wsdlBinding.Extensions.Add(soapBinding); return(soapBinding); }
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); } }
private void DisplayOperations(TreeNode treeNode, System.Web.Services.Description.Binding binding) { int treeNodeCounter = 0; foreach (PortType portType in _serviceDescription.PortTypes) { if (portType.Name == binding.Type.Name) { foreach (Operation operation in portType.Operations) { treeNode.Nodes.Add(operation.Name).Tag = operation; DisplayRequests(treeNode.Nodes[treeNodeCounter], operation); treeNodeCounter++; } } } }
// ----------------------------------------------------------------------------------------------------------------------- // Developers Note: We go through a little song an dance here to Get or Create an exsisting SoapBinding from the WSDL // Extensions for a number of reasons: // 1. Multiple Extensions may contribute to the settings in the soap binding and so to make this work without // relying on ordering, we need the GetOrCreate method. // 2. There are diffrent classes for diffrent SOAP versions and the extensions that determines the version is // also un-ordered so when we finally figure out the version we may need to recreate the BindingExtension and // clone it. internal static WsdlNS.SoapAddressBinding GetOrCreateSoapAddressBinding(WsdlNS.Binding wsdlBinding, WsdlNS.Port wsdlPort, WsdlExporter exporter) { if (GetSoapVersionState(wsdlBinding, exporter) == EnvelopeVersion.None) { return(null); } WsdlNS.SoapAddressBinding existingSoapAddressBinding = GetSoapAddressBinding(wsdlPort); EnvelopeVersion version = GetSoapVersion(wsdlBinding); if (existingSoapAddressBinding != null) { return(existingSoapAddressBinding); } WsdlNS.SoapAddressBinding soapAddressBinding = CreateSoapAddressBinding(version, wsdlPort); return(soapAddressBinding); }
void CheckBasicHttpBinding(WSServiceDescription wsd, string binding_name, XmlQualifiedName binding_type, string operation_name, string action, bool has_input, bool has_output, string label) { WSBinding b = GetBinding(wsd, binding_name, label); OperationBinding op = GetOperationBinding(b, operation_name, label + " CheckBasicHttpBinding"); Assert.AreEqual(binding_type, b.Type, label + " #cbh0"); if (has_input) { InputBinding inb = op.Input; Assert.IsNotNull(inb, label + " #cbh1"); Assert.AreEqual(1, inb.Extensions.Count, label + " #cbh2"); Assert.AreEqual(typeof(SoapBodyBinding), inb.Extensions [0].GetType(), label + " #cbh3"); SoapBodyBinding soap_binding = (SoapBodyBinding)inb.Extensions [0]; Assert.AreEqual(SoapBindingUse.Literal, soap_binding.Use, label + " #cbh4"); if (action != null) { Assert.AreEqual(1, op.Extensions.Count, label + " #chb5"); Assert.AreEqual(typeof(SoapOperationBinding), op.Extensions [0].GetType(), label + " #cbh6"); SoapOperationBinding sopb = (SoapOperationBinding)op.Extensions [0]; Assert.AreEqual(action, sopb.SoapAction, label + " #cbh7"); } } if (has_output) { OutputBinding outb = op.Output; Assert.IsNotNull(outb, label + " #cbh10"); Assert.AreEqual(1, outb.Extensions.Count, label + " #cbh11"); Assert.AreEqual(typeof(SoapBodyBinding), outb.Extensions [0].GetType(), label + " #cbh12"); SoapBodyBinding soap_binding = (SoapBodyBinding)outb.Extensions [0]; Assert.AreEqual(SoapBindingUse.Literal, soap_binding.Use, label + " #cbh13"); } Assert.AreEqual(1, b.Extensions.Count, label + " #cbh20"); Assert.AreEqual(typeof(SoapBinding), b.Extensions [0].GetType(), label + " #cbh21"); SoapBinding sb = (SoapBinding)b.Extensions [0]; Assert.AreEqual(SoapBinding.HttpTransport, sb.Transport, label + " #cbh22"); }
internal static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, Binding b) { checker.Check (ctx, b); CheckExtensions (ctx, checker, b.Extensions); foreach (OperationBinding oper in b.Operations) { CheckExtensions (ctx, checker, oper.Extensions); foreach (MessageBinding mb in oper.Faults) { checker.Check (ctx, mb); CheckExtensions (ctx, checker, mb.Extensions); } checker.Check (ctx, oper.Input); CheckExtensions (ctx, checker, oper.Input.Extensions); checker.Check (ctx, oper.Output); CheckExtensions (ctx, checker, oper.Output.Extensions); } }
/// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="BindingCollection.CopyTo"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void CopyTo(Binding[] array, int index) { List.CopyTo(array, index); }
internal OperationBindingCollection(Binding binding) : base(binding) { }
/// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="BindingCollection.Contains"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public bool Contains(Binding binding) { return List.Contains(binding); }
/// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="BindingCollection.Remove"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Remove(Binding binding) { List.Remove(binding); }
void MoveToBinding(Service service, Port port, Binding binding, PortType portType) { this.service = service; this.port = port; this.portType = portType; this.binding = binding; this.encodedBinding = false; }
/// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="BindingCollection.IndexOf"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public int IndexOf(Binding binding) { return List.IndexOf(binding); }
void MoveToBinding(Binding binding, PortType portType) { MoveToBinding(null, null, binding, portType); }
Port ExportService (WSServiceDescription sd, WSBinding ws_binding, EndpointAddress address, bool msg_version_none) { if (address == null) return null; Service ws_svc = GetService (sd, "service"); sd.Name = "service"; Port ws_port = new Port (); ws_port.Name = ws_binding.Name; ws_port.Binding = new QName (ws_binding.Name, sd.TargetNamespace); if (!msg_version_none) { SoapAddressBinding soap_addr = new SoapAddressBinding (); soap_addr.Location = address.Uri.AbsoluteUri; ws_port.Extensions.Add (soap_addr); } ws_svc.Ports.Add (ws_port); return ws_port; }
Port ExportService (WSServiceDescription sd, WSBinding ws_binding, EndpointAddress address) { if (address == null) return null; Service ws_svc = GetService (sd, "service"); sd.Name = "service"; Port ws_port = new Port (); ws_port.Name = ws_binding.Name; ws_port.Binding = new QName (ws_binding.Name, sd.TargetNamespace); ws_svc.Ports.Add (ws_port); return ws_port; }
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; }
internal void SetParent (Binding binding) { this.binding = binding; }
WsdlNS.Binding CreateWsdlBindingAndPort(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, out WsdlNS.Port wsdlPort, out bool newBinding, out bool bindingNameWasUniquified) { WsdlNS.ServiceDescription bindingWsdl; WsdlNS.Binding wsdlBinding; WsdlEndpointConversionContext bindingConversionContext; XmlQualifiedName wsdlBindingQName; XmlQualifiedName wsdlPortTypeQName; bool printWsdlDeclaration = IsWsdlExportable(endpoint.Binding); if (!exportedBindings.TryGetValue(new BindingDictionaryKey(endpoint.Contract, endpoint.Binding), out bindingConversionContext)) { wsdlBindingQName = WsdlNamingHelper.GetBindingQName(endpoint, this, out bindingNameWasUniquified); bindingWsdl = GetOrCreateWsdl(wsdlBindingQName.Namespace); wsdlBinding = new WsdlNS.Binding(); wsdlBinding.Name = wsdlBindingQName.Name; newBinding = true; WsdlNS.PortType wsdlPortType = exportedContracts[endpoint.Contract].WsdlPortType; wsdlPortTypeQName = new XmlQualifiedName(wsdlPortType.Name, wsdlPortType.ServiceDescription.TargetNamespace); wsdlBinding.Type = wsdlPortTypeQName; if (printWsdlDeclaration) { bindingWsdl.Bindings.Add(wsdlBinding); } WsdlExporter.EnsureWsdlContainsImport(bindingWsdl, wsdlPortTypeQName.Namespace); } else { wsdlBindingQName = new XmlQualifiedName(bindingConversionContext.WsdlBinding.Name, bindingConversionContext.WsdlBinding.ServiceDescription.TargetNamespace); bindingNameWasUniquified = false; bindingWsdl = wsdlDocuments[wsdlBindingQName.Namespace]; wsdlBinding = bindingWsdl.Bindings[wsdlBindingQName.Name]; wsdlPortTypeQName = wsdlBinding.Type; newBinding = false; } //We can only create a Port if there is an address if (endpoint.Address != null) { WsdlNS.Service wsdlService = GetOrCreateWsdlService(wsdlServiceQName); wsdlPort = new WsdlNS.Port(); string wsdlPortName = WsdlNamingHelper.GetPortName(endpoint, wsdlService); wsdlPort.Name = wsdlPortName; wsdlPort.Binding = wsdlBindingQName; WsdlNS.SoapAddressBinding addressBinding = SoapHelper.GetOrCreateSoapAddressBinding(wsdlBinding, wsdlPort, this); if (addressBinding != null) { addressBinding.Location = endpoint.Address.Uri.AbsoluteUri; } WsdlExporter.EnsureWsdlContainsImport(wsdlService.ServiceDescription, wsdlBindingQName.Namespace); if (printWsdlDeclaration) { wsdlService.Ports.Add(wsdlPort); } } else { wsdlPort = null; } return wsdlBinding; }
PolicyConversionContext ExportPolicy (ServiceEndpoint endpoint, WSBinding binding) { var context = new CustomPolicyConversionContext (endpoint); var elements = endpoint.Binding.CreateBindingElements (); foreach (var element in elements) { var exporter = element as IPolicyExportExtension; if (exporter == null) continue; try { exporter.ExportPolicy (this, context); } catch (Exception ex) { var error = AddError ( "Failed to export endpoint '{0}': policy exporter " + "'{1}' threw an exception: {2}", endpoint.Name, element.GetType (), ex); throw new MetadataExportException (error, ex); } } var assertions = context.GetBindingAssertions (); if (assertions.Count == 0) return context; var doc = new XmlDocument (); var policy = doc.CreateElement ("wsp", "Policy", PolicyImportHelper.PolicyNS); doc.AppendChild (policy); var exactlyOne = doc.CreateElement ("wsp", "ExactlyOne", PolicyImportHelper.PolicyNS); var all = doc.CreateElement ("wsp", "All", PolicyImportHelper.PolicyNS); policy.AppendChild (exactlyOne); exactlyOne.AppendChild (all); foreach (var assertion in assertions) { var imported = doc.ImportNode (assertion, true); all.AppendChild (imported); } binding.Extensions.Add (policy); return context; }
internal void SetParent(Binding parent) { this.parent = parent; }
/// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="BindingCollection.Add"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public int Add(Binding binding) { return List.Add(binding); }
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); }
/// <include file='doc\ServiceDescription.uex' path='docs/doc[@for="BindingCollection.Insert"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Insert(int index, Binding binding) { List.Insert(index, binding); }
bool ImportBindingContent (ServiceDescription desc, TypeStubInfo typeInfo, string url, BindingInfo binfo) { serviceDescription = desc; // Look for an unused name int n=0; string name = binfo.Name; bool found; do { found = false; foreach (Binding bi in desc.Bindings) if (bi.Name == name) { found = true; n++; name = binfo.Name+n; break; } } while (found); // Create the binding binding = new Binding (); binding.Name = name; binding.Type = new XmlQualifiedName (binding.Name, binfo.Namespace); if (binfo.WebServiceBindingAttribute != null && binfo.WebServiceBindingAttribute.EmitConformanceClaims) { XmlDocument doc = new XmlDocument (); XmlElement docElement = doc.CreateElement ("wsdl", "documentation", "http://schemas.xmlsoap.org/wsdl/"); XmlElement claimsElement = doc.CreateElement ("wsi", "Claim", "http://ws-i.org/schemas/conformanceClaim/"); claimsElement.Attributes.Append (doc.CreateAttribute ("conformsTo")).Value = "http://ws-i.org/profiles/basic/1.1"; docElement.AppendChild (claimsElement); binding.DocumentationElement = docElement; } portType = new PortType (); portType.Name = binding.Name; BeginClass (); foreach (SoapExtensionReflector reflector in extensionReflectors) { reflector.ReflectionContext = this; reflector.ReflectDescription (); } foreach (MethodStubInfo method in typeInfo.Methods) { methodStubInfo = method; string metBinding = ReflectMethodBinding (); if (typeInfo.GetBinding (metBinding) != binfo) continue; operation = new Operation (); operation.Name = method.OperationName; operation.Documentation = method.MethodAttribute.Description; // FIXME: SOAP 1.1 and SOAP 1.2 should share // the same message definitions. inputMessage = new Message (); inputMessage.Name = method.Name + ProtocolName + "In"; ServiceDescription.Messages.Add (inputMessage); outputMessage = new Message (); outputMessage.Name = method.Name + ProtocolName + "Out"; ServiceDescription.Messages.Add (outputMessage); OperationInput inOp = new OperationInput (); if (method.Name != method.OperationName) inOp.Name = method.Name; Operation.Messages.Add (inOp); inOp.Message = new XmlQualifiedName (inputMessage.Name, ServiceDescription.TargetNamespace); OperationOutput outOp = new OperationOutput (); if (method.Name != method.OperationName) outOp.Name = method.Name; Operation.Messages.Add (outOp); outOp.Message = new XmlQualifiedName (outputMessage.Name, ServiceDescription.TargetNamespace); portType.Operations.Add (operation); ImportOperationBinding (); if (!ReflectMethod ()) { // (It is somewhat hacky) If we don't // add input/output Messages, update // portType/input/@message and // porttype/output/@message. Message dupIn = Parent.MappedMessagesIn [method.MethodInfo]; ServiceDescription.Messages.Remove (inputMessage); inOp.Message = new XmlQualifiedName (dupIn.Name, ServiceDescription.TargetNamespace); Message dupOut = Parent.MappedMessagesOut [method.MethodInfo]; ServiceDescription.Messages.Remove (outputMessage); outOp.Message = new XmlQualifiedName (dupOut.Name, ServiceDescription.TargetNamespace); } foreach (SoapExtensionReflector reflector in extensionReflectors) { reflector.ReflectionContext = this; reflector.ReflectMethod (); } } EndClass (); if (portType.Operations.Count > 0) { desc.Bindings.Add (binding); desc.PortTypes.Add (portType); return true; } else return false; }
OperationBinding GetOperationBinding (WSBinding b, string name, string label) { foreach (OperationBinding op in b.Operations) if (op.Name == name) return op; Assert.Fail (String.Format ("[{0}] OperationBinding named '{1}' not found.", label, name)); return null; }