private static void GenerateCodeDomTree(WsdlImporter wsdlImporter, ServiceContractGenerator contractGenerator) { Collection<ContractDescription> contracts = wsdlImporter.ImportAllContracts(); Collection<Binding> bindings = wsdlImporter.ImportAllBindings(); ServiceEndpointCollection endpoints = wsdlImporter.ImportAllEndpoints(); if (wsdlImporter.Errors.Any(e => !e.IsWarning)) { throw new CodeGenerationException(wsdlImporter.Errors); } foreach (ContractDescription contract in contracts) { //TODO:Alex:Make the naming scheme customisable. contract.Name = "I" + contract.Name.Replace("Interface", string.Empty); contractGenerator.GenerateServiceContractType(contract); } foreach (Binding binding in bindings) { string bindingSectionName, configurationName; contractGenerator.GenerateBinding(binding, out bindingSectionName, out configurationName); } foreach (ServiceEndpoint endpoint in endpoints) { ChannelEndpointElement channelElement; contractGenerator.GenerateServiceEndpoint(endpoint, out channelElement); } }
public ServiceMetadataInformation ImportMetadata(Collection<MetadataSection> metadataCollection, MetadataImporterSerializerFormatMode formatMode) { CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); CodeDomProvider codeDomProvider = m_CodeDomProviderFactory.CreateProvider(); WsdlImporter importer = new WsdlImporter(new MetadataSet(metadataCollection)); switch (formatMode) { case MetadataImporterSerializerFormatMode.DataContractSerializer: AddStateForDataContractSerializerImport(importer, formatMode, codeCompileUnit, codeDomProvider); break; case MetadataImporterSerializerFormatMode.XmlSerializer: AddStateForXmlSerializerImport(importer, codeCompileUnit, codeDomProvider); break; case MetadataImporterSerializerFormatMode.Auto: AddStateForDataContractSerializerImport(importer, formatMode, codeCompileUnit, codeDomProvider); AddStateForXmlSerializerImport(importer, codeCompileUnit, codeDomProvider); break; } if (!importer.State.ContainsKey(typeof(WrappedOptions))) { importer.State.Add(typeof(WrappedOptions), new WrappedOptions { WrappedFlag = false }); } Collection<Binding> bindings = importer.ImportAllBindings(); Collection<ContractDescription> contracts = importer.ImportAllContracts(); ServiceEndpointCollection endpoints = importer.ImportAllEndpoints(); Collection<MetadataConversionError> importErrors = importer.Errors; bool success = true; if (importErrors != null) { foreach (MetadataConversionError error in importErrors) { if (!error.IsWarning) { success = false; break; } } } if (!success) { //TODO: Throw exception } return new ServiceMetadataInformation(codeCompileUnit, codeDomProvider) { Bindings = bindings, Contracts = contracts, Endpoints = endpoints }; }
public static void Run(Uri uri, string cache) { ServicePointManager.ServerCertificateValidationCallback = Validator; MetadataSet doc; string tempfile = null; bool needsDownload; if (cache == null) { needsDownload = true; tempfile = Path.GetTempFileName (); cache = tempfile; } else { needsDownload = !File.Exists (cache); } if (needsDownload) { Console.WriteLine ("Downloading service metadata ..."); DownloadXml (uri, cache); Console.WriteLine ("Downloaded service metadata into {0}.", cache); } try { doc = LoadMetadata (uri, cache); } finally { if (tempfile != null) File.Delete (tempfile); } var importer = new WsdlImporter (doc); var bindings = importer.ImportAllBindings (); var endpoints = importer.ImportAllEndpoints (); foreach (var error in importer.Errors) { if (error.IsWarning) Console.WriteLine ("WARNING: {0}", error.Message); else Console.WriteLine ("ERROR: {0}", error.Message); } Console.WriteLine ("DONE IMPORTING: {0} {1}", bindings.Count, endpoints.Count); foreach (var binding in bindings) Console.WriteLine ("BINDING: {0}", binding); foreach (var endpoint in endpoints) Console.WriteLine ("ENDPOINT: {0}", endpoint.Address); foreach (var endpoint in endpoints) { try { Run (endpoint); } catch (Exception ex) { Console.WriteLine ("ERROR ({0}): {1}", endpoint.Address, ex); } } }
public WebService(string path) { var metadataAddress = new EndpointAddress(path); var mexClient = new MetadataExchangeClient(metadataAddress.Uri, MetadataExchangeClientMode.HttpGet); mexClient.ResolveMetadataReferences = true; var metadata = mexClient.GetMetadata(metadataAddress.Uri, MetadataExchangeClientMode.HttpGet); var metadataSet = new MetadataSet(metadata.MetadataSections); var importer = new WsdlImporter(metadataSet); AllWsdlDocuments = importer.WsdlDocuments; AllContracts = importer.ImportAllContracts(); AllBindings = importer.ImportAllBindings(); AllEndpoints = importer.ImportAllEndpoints(); //AllContracts.First().Operations.First(). }
/// <summary> /// Given a WSDL importer, a set of metadata files and a compile unit, import the metadata /// files. /// </summary> /// <param name="importer"></param> /// <param name="compileUnit"></param> /// <param name="generationErrors"> /// Errors encountered whie importing the model. Any new errors will be appended to this list. /// </param> /// <param name="serviceEndpointList">List of endpoints imported</param> /// <param name="bindingCollection">The collection of bindings imported</param> /// <param name="contractCollection">The collection of contracts imported</param> protected static void ImportWCFModel(WsdlImporter importer, System.CodeDom.CodeCompileUnit compileUnit, IList<ProxyGenerationError> generationErrors, out List<ServiceEndpoint> serviceEndpointList, out IEnumerable<System.ServiceModel.Channels.Binding> bindingCollection, out IEnumerable<ContractDescription> contractCollection) { // We want to remove soap1.2 endpoints for ASMX references, but we can't use the "normal" way // of using a IWsdlImportExtension to do so since BeforeImport is called too late (DevDiv 7857) // If DevDiv 7857 is fixed, we can remove the following two lines and instead add the // AsmxEndpointPickerExtension to the importer's wsdl import extensions... IWsdlImportExtension asmxFixerUpper = new AsmxEndpointPickerExtension(); asmxFixerUpper.BeforeImport(importer.WsdlDocuments, null, null); // NOTE: we should import Endpoint before Contracts, otherwise some information (related to binding) will be lost in the model (devdiv: 22396) serviceEndpointList = new List<ServiceEndpoint>(); // // First we import all the endpoints (ports). This is required so that any WsdlImportExtension's BeforeImport // gets called before we actually try to import anything from the WSDL object model. // If we don't do this, we run into problems if any wsdl import extensions want to delete a specific port // and this port happens to be the first port we try to import (you can't interrupt the import) importer.ImportAllEndpoints(); // // We need to go through each endpoint element and "re-import" it in order to get the mapping // between the wsdlPort and the ServiceEndpoint... Importing the same endpoint twice is a no-op // as far as the endpoint collection is concerned - it is simply a hashtable lookup to retreive // the already generated information... // foreach (System.Web.Services.Description.ServiceDescription wsdlServiceDescription in importer.WsdlDocuments) { foreach (System.Web.Services.Description.Service wsdlService in wsdlServiceDescription.Services) { foreach (System.Web.Services.Description.Port servicePort in wsdlService.Ports) { try { ServiceEndpoint newEndpoint = importer.ImportEndpoint(servicePort); serviceEndpointList.Add(newEndpoint); } catch (InvalidOperationException) { // Invalid operation exceptions should already be in the errors collection for the importer, so we don't // need to add another generationError. The most probable cause for this is that the we failed to import // the endpoint... } catch (Exception ex) { // It is bad, because WsdlImporter.WsdlImportException is a private class generationErrors.Add(new ProxyGenerationError(ProxyGenerationError.GeneratorState.GenerateCode, wsdlServiceDescription.RetrievalUrl, ex)); } } } } bindingCollection = importer.ImportAllBindings(); System.Diagnostics.Debug.Assert(bindingCollection != null, "The importer should never return a NULL binding collection!"); contractCollection = importer.ImportAllContracts(); System.Diagnostics.Debug.Assert(contractCollection != null, "The importer should never return a NULL contract collection!"); foreach (MetadataConversionError error in importer.Errors) { generationErrors.Add(new ProxyGenerationError(error)); } }
public static void NetTcpBinding ( TestContext context, MetadataSet doc, SecurityMode security, bool reliableSession, TransferMode transferMode, TestLabel label) { label.EnterScope ("netTcpBinding"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); WS.Soap12Binding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.Soap12Binding) soap = (WS.Soap12Binding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, "http://schemas.microsoft.com/soap/tcp", label); label.EnterScope ("policy-xml"); Assert.That (xml, Is.Not.Null, label.Get ()); var assertions = AssertPolicy (sd, xml, label); Assert.That (assertions, Is.Not.Null, label.Get ()); AssertPolicy (assertions, BinaryEncodingQName, label); AssertPolicy (assertions, UsingAddressingQName, label); if (transferMode == TransferMode.Streamed) AssertPolicy (assertions, StreamedTransferQName, label); switch (security) { case SecurityMode.Message: AssertPolicy (assertions, SymmetricBindingQName, label); AssertPolicy (assertions, Wss11QName, label); AssertPolicy (assertions, Trust10QName, label); break; case SecurityMode.Transport: AssertPolicy (assertions, TransportBindingQName, label); break; case SecurityMode.TransportWithMessageCredential: AssertPolicy (assertions, TransportBindingQName, label); AssertPolicy (assertions, EndorsingSupportingQName, label); AssertPolicy (assertions, Wss11QName, label); AssertPolicy (assertions, Trust10QName, label); break; default: break; } if (reliableSession) AssertPolicy (assertions, ReliableSessionQName, label); Assert.That (assertions.Count, Is.EqualTo (0), label.Get ()); label.LeaveScope (); label.EnterScope ("services"); Assert.That (sd.Services, Is.Not.Null, label.Get ()); Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ()); var service = sd.Services [0]; Assert.That (service.Ports, Is.Not.Null, label.Get ()); Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ()); var port = service.Ports [0]; label.EnterScope ("port"); Assert.That (port.Extensions, Is.Not.Null, label.Get ()); Assert.That (port.Extensions.Count, Is.EqualTo (2), label.Get ()); WS.Soap12AddressBinding soap_addr_binding = null; XmlElement port_xml = null; foreach (var extension in port.Extensions) { if (extension is WS.Soap12AddressBinding) soap_addr_binding = (WS.Soap12AddressBinding)extension; else if (extension is XmlElement) port_xml = (XmlElement)extension; else Assert.Fail (label.Get ()); } Assert.That (soap_addr_binding, Is.Not.Null, label.Get ()); Assert.That (port_xml, Is.Not.Null, label.Get ()); Assert.That (port_xml.NamespaceURI, Is.EqualTo (Wsa10Namespace), label.Get ()); Assert.That (port_xml.LocalName, Is.EqualTo ("EndpointReference"), label.Get ()); label.LeaveScope (); label.LeaveScope (); label.LeaveScope (); // wsdl var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); CheckNetTcpBinding ( bindings [0], security, reliableSession, transferMode, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); CheckEndpoint (endpoints [0], MetadataSamples.NetTcpUri, label); label.LeaveScope (); label.LeaveScope (); }
static void BasicHttpBinding_inner ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, bool isHttps, TestLabel label) { var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); bool hasPolicyXml; switch (security) { case BasicHttpSecurityMode.None: if (isHttps) throw new InvalidOperationException (); hasPolicyXml = encoding == WSMessageEncoding.Mtom; break; case BasicHttpSecurityMode.Message: case BasicHttpSecurityMode.Transport: case BasicHttpSecurityMode.TransportWithMessageCredential: if (encoding == WSMessageEncoding.Mtom) throw new InvalidOperationException (); hasPolicyXml = true; break; case BasicHttpSecurityMode.TransportCredentialOnly: if (isHttps) throw new InvalidOperationException (); hasPolicyXml = true; break; default: throw new InvalidOperationException (); } label.LeaveScope (); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label); label.LeaveScope (); label.EnterScope ("policy-xml"); if (!hasPolicyXml) Assert.That (xml, Is.Null, label.Get ()); else { Assert.That (xml, Is.Not.Null, label.Get ()); var assertions = AssertPolicy (sd, xml, label); Assert.That (assertions, Is.Not.Null, label.Get ()); if (clientCred == HttpClientCredentialType.Ntlm) AssertPolicy (assertions, NtlmAuthenticationQName, label); if (encoding == WSMessageEncoding.Mtom) AssertPolicy (assertions, MtomEncodingQName, label); switch (security) { case BasicHttpSecurityMode.Message: AssertPolicy (assertions, AsymmetricBindingQName, label); AssertPolicy (assertions, Wss10QName, label); break; case BasicHttpSecurityMode.Transport: AssertPolicy (assertions, TransportBindingQName, label); break; case BasicHttpSecurityMode.TransportWithMessageCredential: AssertPolicy (assertions, SignedSupportingQName, label); AssertPolicy (assertions, TransportBindingQName, label); AssertPolicy (assertions, Wss10QName, label); break; default: break; } Assert.That (assertions.Count, Is.EqualTo (0), label.Get ()); } label.LeaveScope (); label.EnterScope ("services"); Assert.That (sd.Services, Is.Not.Null, label.Get ()); Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ()); var service = sd.Services [0]; Assert.That (service.Ports, Is.Not.Null, label.Get ()); Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ()); var port = service.Ports [0]; label.EnterScope ("port"); Assert.That (port.Extensions, Is.Not.Null, label.Get ()); Assert.That (port.Extensions.Count, Is.EqualTo (1), label.Get ()); WS.SoapAddressBinding soap_addr_binding = null; foreach (var extension in port.Extensions) { if (extension is WS.SoapAddressBinding) soap_addr_binding = (WS.SoapAddressBinding)extension; else Assert.Fail (label.Get ()); } Assert.That (soap_addr_binding, Is.Not.Null, label.Get ()); label.LeaveScope (); label.LeaveScope (); // wsdl var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); string scheme; if ((security == BasicHttpSecurityMode.Transport) || (security == BasicHttpSecurityMode.TransportWithMessageCredential)) scheme = "https"; else scheme = "http"; CheckBasicHttpBinding ( bindings [0], scheme, security, encoding, clientCred, authScheme, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); var uri = isHttps ? MetadataSamples.HttpsUri : MetadataSamples.HttpUri; CheckEndpoint (endpoints [0], uri, label); label.LeaveScope (); }
private void ImportMetadata(WsdlImporter wsdlImporter, out ServiceEndpointCollection endpoints, out Collection<System.ServiceModel.Channels.Binding> bindings, out Collection<ContractDescription> contracts) { endpoints = wsdlImporter.ImportAllEndpoints(); bindings = wsdlImporter.ImportAllBindings(); contracts = wsdlImporter.ImportAllContracts(); ThrowOnMetadataConversionErrors(wsdlImporter.Errors); }
private void ImportMetadata() { this.codeCompileUnit = new CodeCompileUnit(); CreateCodeDomProvider(); WsdlImporter importer = new WsdlImporter(new MetadataSet(metadataCollection)); AddStateForDataContractSerializerImport(importer); AddStateForXmlSerializerImport(importer); this.bindings = importer.ImportAllBindings(); this.contracts = importer.ImportAllContracts(); this.endpoints = importer.ImportAllEndpoints(); this.importWarnings = importer.Errors; bool success = true; if (this.importWarnings != null) { foreach (MetadataConversionError error in this.importWarnings) { if (!error.IsWarning) { success = false; break; } } } if (!success) { DynamicProxyException exception = new DynamicProxyException( Constants.ErrorMessages.ImportError); exception.MetadataImportErrors = this.importWarnings; throw exception; } }
internal static Binding GetBindingFromMetadata(EndpointDiscoveryMetadata metadata) { var metadataExtension = (from extension in metadata.Extensions where extension.Name == WcfConstants.EndpointMetadata select extension).FirstOrDefault(); if (metadataExtension == null) return null; var endpointMetadata = metadataExtension.Elements().FirstOrDefault(); if (endpointMetadata == null) return null; using (var xmlReader = endpointMetadata.CreateReader()) { var metadataSet = MetadataSet.ReadFrom(xmlReader); var importer = new WsdlImporter(metadataSet); return importer.ImportAllBindings().FirstOrDefault(); } }
public void BasicHttpBinding_Error () { var label = new TestLabel ("BasicHttpBinding_Error"); var doc = TestContext.LoadMetadata ("http-error.xml"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; var wsdlBinding = sd.Bindings [0]; var importer = new WsdlImporter (doc); label.EnterScope ("all"); var bindings = importer.ImportAllBindings (); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (0), label.Get ()); label.EnterScope ("errors"); Assert.That (importer.Errors, Is.Not.Null, label.Get ()); Assert.That (importer.Errors.Count, Is.EqualTo (1), label.Get ()); var error = importer.Errors [0]; Assert.That (error.IsWarning, Is.False, label.Get ()); label.LeaveScope (); label.LeaveScope (); label.EnterScope ("single"); try { importer.ImportBinding (wsdlBinding); Assert.Fail (label.Get ()); } catch { ; } Assert.That (importer.Errors.Count, Is.EqualTo (1), label.Get ()); label.LeaveScope (); label.EnterScope ("single-first"); var importer2 = new WsdlImporter (doc); try { importer2.ImportBinding (wsdlBinding); Assert.Fail (label.Get ()); } catch { ; } Assert.That (importer2.Errors.Count, Is.EqualTo (1), label.Get ()); try { importer2.ImportBinding (wsdlBinding); Assert.Fail (label.Get ()); } catch { ; } var bindings2 = importer.ImportAllBindings (); Assert.That (bindings2, Is.Not.Null, label.Get ()); Assert.That (bindings2.Count, Is.EqualTo (0), label.Get ()); label.LeaveScope (); }
private void AssertMetadataForWsHttp(MetadataSet metadata) { WsdlImporter importer = new WsdlImporter(metadata); Collection<ContractDescription> contracts = importer.ImportAllContracts(); Collection<Binding> bindings = importer.ImportAllBindings(); ServiceEndpointCollection endpoints = importer.ImportAllEndpoints(); Assert.IsTrue(metadata.MetadataSections.Count == 4 || metadata.MetadataSections.Count == 5); Assert.AreEqual(0, importer.Errors.Count); Assert.AreEqual(1, contracts.Count); Assert.AreEqual(1, bindings.Count); Assert.AreEqual(1, endpoints.Count); Assert.AreEqual("IMyService", contracts[0].Name); Assert.AreEqual(typeof(WSHttpBinding), bindings[0].GetType()); }
public static void NetTcpBinding ( TestContext context, MetadataSet doc, SecurityMode security, bool reliableSession, TransferMode transferMode, TestLabel label) { label.EnterScope ("netTcpBinding"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); label.EnterScope ("extensions"); Assert.That (sd.Extensions, Is.Not.Null, label.Get ()); Assert.That (sd.Extensions.Count, Is.EqualTo (1), label.Get ()); Assert.That (sd.Extensions [0], Is.InstanceOfType (typeof(XmlElement)), label.Get ()); var extension = (XmlElement)sd.Extensions [0]; Assert.That (extension.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (extension.LocalName, Is.EqualTo ("Policy"), label.Get ()); label.LeaveScope (); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, "http://schemas.microsoft.com/soap/tcp", label); if (context.CheckPolicyXml) { label.EnterScope ("policy-xml"); Assert.That (xml, Is.Not.Null, label.Get ()); Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ()); label.LeaveScope (); } label.LeaveScope (); // wsdl var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); CheckNetTcpBinding ( bindings [0], security, reliableSession, transferMode, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); CheckEndpoint (endpoints [0], MetadataSamples.NetTcpUri, label); label.LeaveScope (); label.LeaveScope (); }
public static void BasicHttpsBinding ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, TestLabel label) { label.EnterScope ("basicHttpsBinding"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); Assert.That (sd.Extensions, Is.Not.Null, label.Get ()); Assert.That (sd.Extensions.Count, Is.EqualTo (1), label.Get ()); Assert.That (sd.Extensions [0], Is.InstanceOfType (typeof(XmlElement)), label.Get ()); label.EnterScope ("extensions"); var extension = (XmlElement)sd.Extensions [0]; Assert.That (extension.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (extension.LocalName, Is.EqualTo ("Policy"), label.Get ()); label.LeaveScope (); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); label.LeaveScope (); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label); if (context.CheckPolicyXml) { label.EnterScope ("policy-xml"); Assert.That (xml, Is.Not.Null, label.Get ()); Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ()); label.LeaveScope (); } label.LeaveScope (); // wsdl var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); CheckBasicHttpBinding ( bindings [0], "https", security, encoding, clientCred, authScheme, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); CheckEndpoint (endpoints [0], MetadataSamples.HttpsUri, label); label.LeaveScope (); label.LeaveScope (); }
public static void BasicHttpBinding ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, TestLabel label) { label.EnterScope ("basicHttpBinding"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); bool hasPolicyXml; switch (security) { case BasicHttpSecurityMode.None: hasPolicyXml = encoding == WSMessageEncoding.Mtom; break; case BasicHttpSecurityMode.Message: case BasicHttpSecurityMode.Transport: case BasicHttpSecurityMode.TransportWithMessageCredential: if (encoding == WSMessageEncoding.Mtom) throw new InvalidOperationException (); hasPolicyXml = true; break; case BasicHttpSecurityMode.TransportCredentialOnly: hasPolicyXml = true; break; default: throw new InvalidOperationException (); } label.LeaveScope (); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label); label.LeaveScope (); label.EnterScope ("policy-xml"); if (!hasPolicyXml) Assert.That (xml, Is.Null, label.Get ()); else if (context.CheckPolicyXml) { Assert.That (xml, Is.Not.Null, label.Get ()); Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ()); } label.LeaveScope (); var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); string scheme; if ((security == BasicHttpSecurityMode.Transport) || (security == BasicHttpSecurityMode.TransportWithMessageCredential)) scheme = "https"; else scheme = "http"; CheckBasicHttpBinding ( bindings [0], scheme, security, encoding, clientCred, authScheme, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); CheckEndpoint (endpoints [0], MetadataSamples.HttpUri, label); label.LeaveScope (); label.LeaveScope (); }