本文整理汇总了C#中System.ServiceModel.Description.MetadataExchangeClient.GetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataExchangeClient.GetMetadata方法的具体用法?C# MetadataExchangeClient.GetMetadata怎么用?C# MetadataExchangeClient.GetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Description.MetadataExchangeClient
的用法示例。
在下文中一共展示了MetadataExchangeClient.GetMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DiscoverMexMetadata
void DiscoverMexMetadata(object sender, DoWorkEventArgs e)
{
Uri url = (Uri)e.Argument;
var client = new MetadataExchangeClient(url, MetadataExchangeClientMode.MetadataExchange);
MetadataSet metadata = client.GetMetadata();
e.Result = new ServiceReferenceDiscoveryEventArgs(metadata);
}
示例2: UseWcf
static void UseWcf()
{
/*
动态下载服务元数据
*/
MetadataExchangeClient metaExchangeClient =
new MetadataExchangeClient(
new Uri("http://localhost:8002/ManualService"),
MetadataExchangeClientMode.HttpGet
);
//下载元数据
MetadataSet metadataSet = metaExchangeClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metadataSet);
ServiceEndpointCollection endpointCollection = importer.ImportAllEndpoints();
IManulService manulProxy = null;
foreach (ServiceEndpoint endPointItem in endpointCollection)
{
manulProxy = new ChannelFactory<IManulService>(
endPointItem.Binding,
endPointItem.Address
).CreateChannel();
((IChannel)manulProxy).Open();
Console.WriteLine("WCF调用结果为:{0}",
manulProxy.GetData());
((IChannel)manulProxy).Close();
}
}
示例3: GenerateVBCodeForService
static void GenerateVBCodeForService(Uri metadataAddress, string outputFile)
{
MetadataExchangeClient mexClient = new MetadataExchangeClient(metadataAddress, MetadataExchangeClientMode.HttpGet);
mexClient.ResolveMetadataReferences = true;
MetadataSet metaDocs = mexClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metaDocs);
ServiceContractGenerator generator = new ServiceContractGenerator();
System.Collections.ObjectModel.Collection<ContractDescription> contracts = importer.ImportAllContracts();
foreach (ContractDescription contract in contracts)
{
generator.GenerateServiceContractType(contract);
}
if (generator.Errors.Count != 0)
throw new ApplicationException("There were errors during code compilation.");
// Write the code dom.
System.CodeDom.Compiler.CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions();
options.BracingStyle = "C";
System.CodeDom.Compiler.CodeDomProvider codeDomProvider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("VB");
System.CodeDom.Compiler.IndentedTextWriter textWriter = new System.CodeDom.Compiler.IndentedTextWriter(new System.IO.StreamWriter(outputFile));
codeDomProvider.GenerateCodeFromCompileUnit(generator.TargetCompileUnit, textWriter, options);
textWriter.Close();
}
示例4: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress, BindingElement bindingElement)
{
var binding = new CustomBinding(bindingElement);
var MEXClient = new MetadataExchangeClient(binding);
var metadata = MEXClient.GetMetadata(new EndpointAddress(mexAddress));
var importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例5: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,Binding binding,TokenProvider tokenProvider)
{
dynamic extendedBinding = binding;
extendedBinding.MaxReceivedMessageSize *= MessageSizeMultiplier;
MetadataExchangeClient mexClient = new MetadataExchangeClient(extendedBinding);
mexClient.SetServiceBusCredentials(tokenProvider);
MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
MetadataImporter importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例6: Main
static void Main(string[] args)
{
Console.WriteLine("URI of the metadata documetns retreived");
//MetadataExchangeClient metaTransfer = new MetadataExchangeClient(new Uri("http://localhost:1169/Service1.svc/mex"), MetadataExchangeClientMode.MetadataExchange);
MetadataExchangeClient metaTransfer = new MetadataExchangeClient(new Uri("http://localhost:1169/Service1.svc"), MetadataExchangeClientMode.HttpGet);
metaTransfer.ResolveMetadataReferences = true;
MetadataSet metadata = metaTransfer.GetMetadata();
foreach (MetadataSection doc in metadata.MetadataSections)
Console.WriteLine(doc.Dialect + " : " + doc.Metadata);
Console.ReadLine();
}
示例7: Main
static void Main(string[] args)
{
MetadataExchangeClient metadataExchangeClient = new MetadataExchangeClient(new Uri("http://127.0.0.1:3721/calculatorservice/metadata"), MetadataExchangeClientMode.HttpGet);
metadataExchangeClient.ResolveMetadataReferences = false;
MetadataSet metadata = metadataExchangeClient.GetMetadata();
using (XmlWriter writer = new XmlTextWriter("metadata.xml", Encoding.UTF8))
{
metadata.WriteTo(writer);
}
Process.Start("metadata.xml");
}
示例8: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,BindingElement bindingElement)
{
dynamic element = bindingElement;
element.MaxReceivedMessageSize *= MessageSizeMultiplier;
CustomBinding binding = new CustomBinding(element);
MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
MetadataImporter importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例9: GetMetaDataDocs
private MetadataSet GetMetaDataDocs(EndpointAddress metadataAddress)
{
var binding = new WSHttpBinding(SecurityMode.Transport);
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
var mexClient = new MetadataExchangeClient(binding)
{
ResolveMetadataReferences = true,
MaximumResolvedReferences = 1000
};
var metaDocs = mexClient.GetMetadata(metadataAddress.Uri, MetadataExchangeClientMode.HttpGet);
return metaDocs;
}
示例10: CreateImporter
private WsdlImporter CreateImporter(EndPointSetting wsdl)
{
var endpoint = new EndpointAddress(wsdl.Uri);
var binding = new WSHttpBinding(SecurityMode.None)
{
MaxReceivedMessageSize = Int32.MaxValue,
};
var mex = new MetadataExchangeClient(binding);
mex.ResolveMetadataReferences = true;
var metaDocs = mex.GetMetadata(new Uri(wsdl.Uri), MetadataExchangeClientMode.HttpGet);
return new WsdlImporter(metaDocs);
}
示例11: 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().
}
示例12: Main
static void Main(string[] args)
{
Binding binding = MetadataExchangeBindings.CreateMexHttpBinding();
EndpointAddress address = new EndpointAddress("http://127.0.0.1:9999/calculatorservice/mex");
MetadataExchangeClient metadataExchangeClient = new MetadataExchangeClient(binding);
MetadataSet metadata = metadataExchangeClient.GetMetadata(address);
WsdlImporter wsdlImporter = new WsdlImporter(metadata);
//添加已知契约类型
ContractDescription contract = ContractDescription.GetContract(typeof(ICalculator));
wsdlImporter.KnownContracts.Add(new XmlQualifiedName(contract.Name, contract.Namespace), contract);
ServiceEndpointCollection endpoints = wsdlImporter.ImportAllEndpoints();
using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>(endpoints[0]))
{
ICalculator calculator = channelFactory.CreateChannel();
Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, calculator.Add(1, 2));
}
Console.Read();
}
示例13: Resolve
public static ServiceEndpointCollection Resolve(IEnumerable<ContractDescription> contracts, Uri address, MetadataExchangeClientMode mode, MetadataExchangeClient client)
{
if (address == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
}
MetadataExchangeClientModeHelper.Validate(mode);
if (client == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("client");
}
if (contracts == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contracts");
}
ValidateContracts(contracts);
MetadataSet metadataSet = client.GetMetadata(address, mode);
return ImportEndpoints(metadataSet, contracts, client);
}
示例14: ResolveWithWSMex
static MetadataSet ResolveWithWSMex (string url)
{
MetadataSet metadata = null;
try {
var client = new MetadataExchangeClient (new EndpointAddress (url));
Console.WriteLine ("\nAttempting to download metadata from {0} using WS-MetadataExchange..", url);
metadata = client.GetMetadata ();
} catch (InvalidOperationException e) {
//MetadataExchangeClient wraps exceptions, thrown while
//fetching the metadata, in an InvalidOperationException
string msg;
msg = e.InnerException == null ? e.Message : e.InnerException.ToString ();
Console.WriteLine ("WS-MetadataExchange query failed for the url '{0}' with exception :\n {1}",
url, msg);
}
return metadata;
}
示例15: GenerateVBCodeForService
static void GenerateVBCodeForService(EndpointAddress metadataAddress, string outputFile)
{
MetadataExchangeClient mexClient = new MetadataExchangeClient(metadataAddress);
mexClient.ResolveMetadataReferences = true;
MetadataSet metaDocs = mexClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metaDocs);
ServiceContractGenerator generator = new ServiceContractGenerator();
// Uncomment the following code if you are going to do your work programmatically rather than add
// the WsdlDocumentationImporters through a configuration file.
/*
// The following code inserts the custom WSDL programmatically adding the custom WsdlImporter without
// removing the other importers already in the collection.
System.Collections.Generic.IEnumerable<IWsdlImportExtension> exts = importer.WsdlExtensions;
System.Collections.Generic.List<IWsdlImportExtension> newExts = new System.Collections.Generic.List<IWsdlImportExtension>();
foreach (IWsdlImportExtension ext in exts)
newExts.Add(ext);
newExts.Add(new WsdlDocumentationImporter());
importer = new WsdlImporter(newExts.ToArray(), metaDocs.MetadataSections);
*/
System.Collections.ObjectModel.Collection<ContractDescription> contracts = importer.ImportAllContracts();
foreach (ContractDescription contract in contracts)
{
generator.GenerateServiceContractType(contract);
}
if (generator.Errors.Count != 0)
throw new ApplicationException("There were errors during code compilation.");
// Write the code dom.
System.CodeDom.Compiler.CodeGeneratorOptions options = new System.CodeDom.Compiler.CodeGeneratorOptions();
options.BracingStyle = "C";
System.CodeDom.Compiler.CodeDomProvider codeDomProvider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("VB");
System.CodeDom.Compiler.IndentedTextWriter textWriter = new System.CodeDom.Compiler.IndentedTextWriter(new System.IO.StreamWriter(outputFile));
codeDomProvider.GenerateCodeFromCompileUnit(generator.TargetCompileUnit, textWriter, options);
textWriter.Close();
}