本文整理汇总了C#中System.ServiceModel.Description.MetadataExchangeClient类的典型用法代码示例。如果您正苦于以下问题:C# MetadataExchangeClient类的具体用法?C# MetadataExchangeClient怎么用?C# MetadataExchangeClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetadataExchangeClient类属于System.ServiceModel.Description命名空间,在下文中一共展示了MetadataExchangeClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginResolve
public static IAsyncResult BeginResolve(IEnumerable<ContractDescription> contracts, System.ServiceModel.EndpointAddress address, MetadataExchangeClient client, AsyncCallback callback, Object asyncState)
{
Contract.Requires(address != null);
Contract.Ensures(Contract.Result<System.IAsyncResult>() != null);
return default(IAsyncResult);
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:7,代码来源:System.ServiceModel.Description.MetadataResolver.cs
示例2: 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();
}
示例3: 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();
}
}
示例4: 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);
}
示例5: 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();
}
示例6: 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");
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: Main
static void Main()
{
// Specify the Metadata Exchange binding and its security mode
WSHttpBinding mexBinding = new WSHttpBinding(SecurityMode.Message);
mexBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
// Create a MetadataExchangeClient for retrieving metadata, and set the certificate details
MetadataExchangeClient mexClient = new MetadataExchangeClient(mexBinding);
mexClient.SoapCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser, StoreName.My,
X509FindType.FindBySubjectName, "client.com");
mexClient.SoapCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
mexClient.SoapCredentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.CurrentUser, StoreName.TrustedPeople,
X509FindType.FindBySubjectName, "localhost");
// The contract we want to fetch metadata for
Collection<ContractDescription> contracts = new Collection<ContractDescription>();
ContractDescription contract = ContractDescription.GetContract(typeof(ICalculator));
contracts.Add(contract);
// Find endpoints for that contract
EndpointAddress mexAddress = new EndpointAddress(ConfigurationManager.AppSettings["mexAddress"]);
ServiceEndpointCollection endpoints = MetadataResolver.Resolve(contracts,
mexAddress, mexClient);
// Communicate with each endpoint that supports the ICalculator contract.
foreach (ServiceEndpoint endpoint in endpoints)
{
if (endpoint.Contract.Namespace.Equals(contract.Namespace) && endpoint.Contract.Name.Equals(contract.Name))
{
// Create a channel and set the certificate details to communicate with the Application endpoint
ChannelFactory<ICalculator> cf = new ChannelFactory<ICalculator>(endpoint.Binding, endpoint.Address);
cf.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My,
X509FindType.FindBySubjectName, "client.com");
cf.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
ICalculator channel = cf.CreateChannel();
// call operations
DoCalculations(channel);
((IChannel)channel).Close();
cf.Close();
}
}
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例11: 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;
}
示例12: 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);
}
示例13: BeginResolve
public static IAsyncResult BeginResolve(IEnumerable<ContractDescription> contracts, EndpointAddress address, MetadataExchangeClient client, AsyncCallback callback, object asyncState)
{
if (address == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
}
if (client == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("client");
}
if (contracts == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contracts");
}
ValidateContracts(contracts);
return new AsyncMetadataResolverHelper(address, MetadataExchangeClientMode.MetadataExchange, client, contracts, callback, asyncState);
}
示例14: 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().
}
示例15: 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();
}