本文整理汇总了C#中System.ServiceModel.Description.WsdlImporter.ImportAllBindings方法的典型用法代码示例。如果您正苦于以下问题:C# WsdlImporter.ImportAllBindings方法的具体用法?C# WsdlImporter.ImportAllBindings怎么用?C# WsdlImporter.ImportAllBindings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Description.WsdlImporter
的用法示例。
在下文中一共展示了WsdlImporter.ImportAllBindings方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCodeDomTree
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);
}
}
示例2: ImportMetadata
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
};
}
示例3: Run
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);
}
}
}
示例4: WebService
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().
}
示例5: ImportWCFModel
/// <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));
}
}
示例6: ImportMetadata
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);
}
示例7: ImportMetadata
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;
}
}
示例8: GetBindingFromMetadata
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();
}
}
示例9: BasicHttpBinding_Error
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 ();
}
示例10: AssertMetadataForWsHttp
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());
}
示例11: NetTcpBinding
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 ();
}
示例12: BasicHttpsBinding
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 ();
}
示例13: BasicHttpBinding
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 ();
}