public void ResolveNoEndpoint() { ServiceEndpointCollection endpoints = MetadataResolver.Resolve( typeof(NonExistantContract), new EndpointAddress(url)); Assert.IsNotNull(endpoints); Assert.AreEqual(0, endpoints.Count); }
public void Resolve2() { ServiceEndpointCollection endpoints = MetadataResolver.Resolve( typeof(IEchoService), new Uri(url), MetadataExchangeClientMode.MetadataExchange); CheckIEchoServiceEndpoint(endpoints); }
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 }; }
private string GetEndpointAddressForNamedEndpoint() { ServiceEndpointCollection endpointCollection; if (!ServiceEndpointCollection.TryParseEndpointsString(this.Endpoint.Address, out endpointCollection)) { // Client has not specified an explicit name for the endpoint, so parse failure is ok. // return the endpoint address. if (this.ListenerName == null) { return(this.Endpoint.Address); } else { throw new FabricInvalidAddressException( string.Format( CultureInfo.InvariantCulture, SR.ErrorInvalidPartitionEndpointAddress, this.Endpoint.Address, this.rsp.Info.Id)); } } string parsedEndpointAddress; // Client has not specified a named endpoint, give the first endpoint in the collection. if (this.ListenerName == null) { if (endpointCollection.TryGetFirstEndpointAddress(out parsedEndpointAddress)) { return(parsedEndpointAddress); } else { throw new FabricInvalidAddressException( string.Format( CultureInfo.InvariantCulture, SR.ErrorInvalidPartitionEndpointAddress, this.Endpoint.Address, this.rsp.Info.Id)); } } if (!endpointCollection.TryGetEndpointAddress(this.ListenerName, out parsedEndpointAddress)) { throw new FabricInvalidAddressException( string.Format( CultureInfo.InvariantCulture, SR.ErrorPartitionNamedEndpointNotFound, this.ListenerName, this.Endpoint.Address, this.rsp.Info.Id)); } return(parsedEndpointAddress); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="WcfServiceHostEventArgs" /> class. /// </summary> /// <param name="name">String of Wcf Service Name.</param> /// <param name="state">Instance of WcfServiceHostStateEnum.</param> /// <param name="endpoints">The endpoints.</param> /// <param name="channelMessage">The unit of communication between endpoints in a distributed environment.</param> /// <param name="message">The Wcf service message.</param> /// <param name="messageId">The message identifier.</param> /// <param name="isOneWay">Whether the message is one way.</param> public WcfServiceHostEventArgs(string name, WcfServiceHostState state, ServiceEndpointCollection endpoints, Message channelMessage, string message, Guid?messageId, bool?isOneWay) { this.Name = name; this.Endpoints = endpoints; this.State = state; this.ChannelMessage = channelMessage; this.Message = message; this.MessageId = messageId ?? Guid.Empty; this.IsOneWay = isOneWay; }
internal ServiceDescription(string serviceName) { this.behaviors = new KeyedByTypeCollection<IServiceBehavior>(); this.endpoints = new ServiceEndpointCollection(); this.serviceNamespace = "http://tempuri.org/"; if (string.IsNullOrEmpty(serviceName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceName"); } this.Name = serviceName; }
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(); }
public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, ServiceEndpointCollection endpointCollection) { if (DiagnosticUtility.ShouldTrace(type)) { foreach (ServiceEndpoint endpoint in endpointCollection) { ComPlusServiceHostCreatedServiceEndpointSchema schema = new ComPlusServiceHostCreatedServiceEndpointSchema(info.AppID, info.Clsid, endpoint.Contract.Name, endpoint.Address.Uri, endpoint.Binding.Name); TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord) schema); } } }
private Dictionary <string, IEnumerable <ServiceEndpoint> > GetEndPointsOfEachServiceContract(WsdlImporter imptr, Collection <ContractDescription> svcCtrDescs) { ServiceEndpointCollection allEP = imptr.ImportAllEndpoints(); var ctrEP = new Dictionary <string, IEnumerable <ServiceEndpoint> >(); foreach (ContractDescription svcCtrDesc in svcCtrDescs) { List <ServiceEndpoint> eps = allEP.Where(x => x.Contract.Name == svcCtrDesc.Name).ToList(); ctrEP.Add(svcCtrDesc.Name, eps); } return(ctrEP); }
private static void DumpEndpoint(ServiceEndpointCollection endpoints) { foreach (ServiceEndpoint sep in endpoints) { Console.Write("Address:{0}\nBinding:{1}\nContract:{2}\n", sep.Address, sep.Binding.Name, sep.Contract); Console.WriteLine("Binding Stack:"); foreach (BindingElement be in sep.Binding.CreateBindingElements()) { Console.WriteLine(be.ToString()); } } }
/// <summary> /// Gets all service endpoints for the contract interface type /// through the MEX exposed endpoint. /// </summary> /// <param name="contractType">The interface type contract of the service.</param> /// <param name="serviceEndpointAddress">The endpoint address of the service MEX.</param> /// <param name="mexMode">The metadata exchange client mode.</param> /// <returns>The collection of service endpoints.</returns> public static ServiceEndpointCollection GetServiceEndpoints(Type contractType, Uri serviceEndpointAddress, MetadataExchangeClientMode mexMode) { // Get all service endpoints for the current contract // at the specified service address, specifically get // the service information from the exposed // MEX (Metadata Exchange) endpoint address. ServiceEndpointCollection serviceEndpoints = MetadataResolver.Resolve(contractType, serviceEndpointAddress, mexMode); // Return the collection of endpoints. return(serviceEndpoints); }
public static void Trace(TraceEventType type, int traceCode, string description, ServiceEndpointCollection serviceEndpointsRetrieved) { if (DiagnosticUtility.ShouldTrace(type)) { int num = 0; ComPlusMexBuilderMetadataRetrievedEndpoint[] endpoints = new ComPlusMexBuilderMetadataRetrievedEndpoint[serviceEndpointsRetrieved.Count]; foreach (ServiceEndpoint endpoint in serviceEndpointsRetrieved) { endpoints[num++] = new ComPlusMexBuilderMetadataRetrievedEndpoint(endpoint); } ComPlusMexBuilderMetadataRetrievedSchema schema = new ComPlusMexBuilderMetadataRetrievedSchema(endpoints); TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord) schema); } }
/// <summary> /// Generates the service model endpoints for the metadata set in the xml file for the application configuration location. /// </summary> /// <param name="metaDocs">The metadata set document.</param> /// <param name="xmlFile">The name of the xml file to write the configuration information to.</param> /// <param name="configuration">The current application configuration file instance.</param> /// <returns>The collection of channel endpoint elements.</returns> public static ChannelEndpointElement[] GenerateServiceModelEndpoints(MetadataSet metaDocs, string xmlFile, System.Configuration.Configuration configuration) { // Make sure the page reference exists. if (metaDocs == null) { throw new ArgumentNullException("metaDocs"); } if (xmlFile == null) { throw new ArgumentNullException("xmlFile"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } WsdlImporter importer = new WsdlImporter(metaDocs); ServiceContractGenerator generator = new ServiceContractGenerator(configuration); // Get all the endpoint type bindings ServiceEndpointCollection serviceEndpoints = importer.ImportAllEndpoints(); // Create a new endpoint collection. List <ChannelEndpointElement> endpointElements = new List <ChannelEndpointElement>(); System.ServiceModel.Configuration.ChannelEndpointElement channelEndpoint = null; // For each endpoint found add the // type to the collection. foreach (ServiceEndpoint serviceEndpoint in serviceEndpoints) { generator.GenerateServiceEndpoint(serviceEndpoint, out channelEndpoint); endpointElements.Add(channelEndpoint); } // If no file has been specified then save to the application configuration // file else save to a new file specified. if (String.IsNullOrEmpty(xmlFile)) { generator.Configuration.Save(); } else { generator.Configuration.SaveAs(xmlFile); } // Return the collection of endpoints. return(endpointElements.ToArray()); }
public void Resolve3() { ContractDescription contract = ContractDescription.GetContract(typeof(IEchoService)); List <ContractDescription> contracts = new List <ContractDescription> (); contracts.Add(contract); ServiceEndpointCollection endpoints = MetadataResolver.Resolve( contracts, new Uri(url), MetadataExchangeClientMode.MetadataExchange); CheckIEchoServiceEndpoint(endpoints); }
static void Main(string[] args) { Uri uri = new Uri("http://10.157.13.69:3336/mex"); MetadataExchangeClient client = new MetadataExchangeClient(uri, MetadataExchangeClientMode.MetadataExchange); MetadataSet metadata = client.GetMetadata(); WsdlImporter importer = new WsdlImporter(metadata); ServiceEndpointCollection endpoints = importer.ImportAllEndpoints(); //ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IService), uri, MetadataExchangeClientMode.MetadataExchange); foreach (var item in endpoints) { Console.WriteLine(item.Address.Uri); } }
/// <summary> /// Run test on all clients /// </summary> /// <typeparam name="TResult">Type name of the result value list</typeparam> /// <param name="asyncAction">Async action to run on all clients</param> /// <returns>Async task</returns> private async Task <TResult[]> RunOnAllClients <TResult>(Func <JobRunnerSvcClient, Task <TResult> > asyncAction) { var results = new List <TResult>(); var serviceName = this.serviceContext.ServiceName; var partitionList = await this.fabricClient.QueryManager.GetPartitionListAsync(serviceName).ConfigureAwait(false); foreach (var partition in partitionList) { var serviceReplicaList = await this.fabricClient.QueryManager.GetReplicaListAsync(partition.PartitionInformation.Id).ConfigureAwait(false); foreach (var replica in serviceReplicaList) { if (!ServiceEndpointCollection.TryParseEndpointsString(replica.ReplicaAddress, out ServiceEndpointCollection endpoints)) { VegaDistTestEventSource.Log.ParseEndpointsStringFailed(replica.ReplicaAddress); continue; } if (!endpoints.TryGetEndpointAddress("GrpcEndpoint", out string jobControlEndpoint)) { VegaDistTestEventSource.Log.GetEndpointAddressFailed("GrpcEndpoint", replica.ReplicaAddress); continue; } Channel channel = null; try { channel = new Channel(jobControlEndpoint.Replace(@"http://", string.Empty), ChannelCredentials.Insecure); JobRunnerSvcClient client = new JobRunnerSvcClient(channel); results.Add(await asyncAction(client).ConfigureAwait(false)); } catch (Exception ex) { VegaDistTestEventSource.Log.RunJobOnClientFailed(jobControlEndpoint, ex.ToString()); } finally { if (channel != null) { await channel.ShutdownAsync(); } } } } return(results.ToArray()); }
/// <summary> /// 根据Contract的名字查找EndPoint /// </summary> /// <param name="endpoints"></param> /// <param name="contractName"></param> /// <returns></returns> public static ServiceEndpoint FindByContractName(this ServiceEndpointCollection endpoints, string contractName) { ServiceEndpoint result = null; foreach (ServiceEndpoint endpoint in endpoints) { if (endpoint.Contract.ConfigurationName == contractName) { result = endpoint; break; } } return(result); }
/// <summary> /// Gets the first endpoint from the array of endpoints within a ResolvedServiceEndpoint. /// </summary> /// <param name="rse">ResolvedServiceEndpoint instance.</param> /// <returns>String containing the replica address.</returns> /// <exception cref="InvalidProgramException">ResolvedServiceEndpoint address list coudln't be parsed or no endpoints exist.</exception> public static string GetFirstEndpoint(this ResolvedServiceEndpoint rse) { ServiceEndpointCollection sec = null; if (ServiceEndpointCollection.TryParseEndpointsString(rse.Address, out sec)) { string replicaAddress; if (sec.TryGetFirstEndpointAddress(out replicaAddress)) { return(replicaAddress); } } throw new InvalidProgramException("ResolvedServiceEndpoint had invalid address"); }
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()); }
private void CheckIEchoServiceEndpoint(ServiceEndpointCollection endpoints) { Assert.IsNotNull(endpoints); Assert.AreEqual(1, endpoints.Count); ServiceEndpoint ep = endpoints [0]; //URI Dependent //Assert.AreEqual ("http://localhost:8080/echo/svc", ep.Address.Uri.AbsoluteUri, "#R1"); Assert.AreEqual("IEchoService", ep.Contract.Name, "#R3"); Assert.AreEqual("http://myns/echo", ep.Contract.Namespace, "#R4"); Assert.AreEqual("BasicHttpBinding_IEchoService", ep.Name, "#R5"); Assert.AreEqual(typeof(BasicHttpBinding), ep.Binding.GetType(), "#R2"); }
private void button1_Click(object sender, EventArgs e) { Uri uri = new Uri(textBox1.Text); ServiceEndpointCollection endpts = MetadataResolver.Resolve(typeof(IEmployeeService), uri, MetadataExchangeClientMode.HttpGet); foreach (ServiceEndpoint obj in endpts) { IEmployeeService proxy = new ChannelFactory <IEmployeeService>(obj.Binding, obj.Address).CreateChannel(); DataSet ds = proxy.GetEmployees(); listBox1.DataSource = ds.Tables[0].DefaultView; listBox1.DisplayMember = "FirstName"; listBox1.ValueMember = "EmployeeID"; ((IChannel)proxy).Close(); } }
async Task <string> IStatefulServiceReplica.ChangeRoleAsync(ReplicaRole newRole, CancellationToken cancellationToken) { ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "ChangeRoleAsync : new role {0}", newRole); await this.CloseCommunicationListenersAsync(cancellationToken); if (newRole == ReplicaRole.Primary) { this.endpointCollection = await this.OpenCommunicationListenersAsync(newRole, cancellationToken); this.userServiceReplica.Addresses = this.endpointCollection.ToReadOnlyDictionary(); this.runAsynCancellationTokenSource = new CancellationTokenSource(); this.executeRunAsyncTask = this.ScheduleRunAsync(this.runAsynCancellationTokenSource.Token); } else { await this.CancelRunAsync(); if (newRole == ReplicaRole.ActiveSecondary) { this.endpointCollection = await this.OpenCommunicationListenersAsync(newRole, cancellationToken); this.userServiceReplica.Addresses = this.endpointCollection.ToReadOnlyDictionary(); } } ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "ChangeRoleAsync : Begin UserServiceReplica change role to {0}", newRole); await this.userServiceReplica.OnChangeRoleAsync(newRole, cancellationToken); ServiceTrace.Source.WriteInfoWithId( TraceType, this.traceId, "ChangeRoleAsync : End UserServiceReplica change role"); await this.stateProviderReplica.ChangeRoleAsync(newRole, cancellationToken); return(this.endpointCollection.ToString()); }
public static string[] GetAddresses(string mexAddress, string contractNamespace, string contractName) { ServiceEndpointCollection endpoints = GetEndpoints(mexAddress); List <string> addresses = new List <string>(); foreach (ServiceEndpoint endpoint in endpoints) { if (endpoint.Contract.Namespace == contractNamespace && endpoint.Contract.Name == contractName) { Debug.Assert(addresses.Contains(endpoint.Address.Uri.AbsoluteUri) == false); addresses.Add(endpoint.Address.Uri.AbsoluteUri); } } return(addresses.ToArray()); }
static void Main(string[] args) { ServiceEndpointCollection serviceEndpointCollection = MetadataResolver.Resolve(typeof(IMachine), new EndpointAddress("http://localhost:8080/ServiceMachine/mex")); foreach (var endpoint in serviceEndpointCollection) { var channel = new MachineClient(endpoint.Binding, endpoint.Address); string machineName = channel.GetMachineName(new MachineDTO { MachineID = "1", MachineName = "test" }); Console.WriteLine(machineName); Console.WriteLine(endpoint.Binding); } }
/// <summary> /// Queries the mex endpoint via HTTP get. /// </summary> /// <param name="mexAddress">The mex address.</param> /// <param name="bindingElement">The binding element.</param> /// <returns>ServiceEndpointCollection.</returns> private static ServiceEndpointCollection QueryMexEndpointViaHttpGet(string mexAddress, TransportBindingElement bindingElement) { ServiceEndpointCollection endpoints = null; if (mexAddress.EndsWith("?wsdl") == false) { mexAddress += "?wsdl"; } var binding = new CustomBinding(bindingElement); var mexClient = new MetadataExchangeClient(binding); var metadata = mexClient.GetMetadata(new Uri(mexAddress), MetadataExchangeClientMode.HttpGet); var importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); return(endpoints); }
public static void Snippet2() { using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService))) { serviceHost.Open(); ServiceEndpointCollection endpoints = serviceHost.Description.Endpoints; ServiceEndpoint endpoint = endpoints.Find(typeof(ICalculator)); NetTcpBinding binding = (NetTcpBinding)endpoint.Binding; // <Snippet2> NetTcpSecurity security = binding.Security; Console.WriteLine("\tSecurity Mode: {0}", security.Mode); // </Snippet2> } }
ServiceEndpointCollection ImportWsdlPortType(XmlQualifiedName portTypeQName, WsdlImporter importer) { foreach (WsdlNS.ServiceDescription wsdl in importer.WsdlDocuments) { if (wsdl.TargetNamespace == portTypeQName.Namespace) { WsdlNS.PortType wsdlPortType = wsdl.PortTypes[portTypeQName.Name]; if (wsdlPortType != null) { ServiceEndpointCollection endpoints = importer.ImportEndpoints(wsdlPortType); return(endpoints); } } } return(new ServiceEndpointCollection()); }
static void Main(string[] args) { EndpointAddress metaAddress = new EndpointAddress(new Uri("http://localhost:1169/Service1.svc/mex")); ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IService1), metaAddress); foreach (ServiceEndpoint point in endpoints) { if (point != null) { using (Service1Client wcfClient = new Service1Client(point.Binding, point.Address)) { Console.WriteLine(wcfClient.GetString(String.Format("binding is {0}, address is {1}", point.Binding, point.Address))); } } } Console.ReadLine(); }
Binding DiscoverBinding <T>() { Binding binding = null; DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint()); FindResponse discovered = discoveryClient.Find(FindCriteria.CreateMexEndpointCriteria()); foreach (EndpointDiscoveryMetadata mexEndpoint in discovered.Endpoints) { Debug.Assert(binding == null); ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IMyContract), mexEndpoint.Address.Uri, MetadataExchangeClientMode.MetadataExchange); Debug.Assert(endpoints.Count == 1); binding = endpoints[0].Binding; } return(binding); }
private DestinationConfig BuildDestination(ReplicaWrapper replica, string listenerName, string healthListenerName, PartitionWrapper partition) { if (!ServiceEndpointCollection.TryParseEndpointsString(replica.ReplicaAddress, out var serviceEndpointCollection)) { throw new ConfigException($"Could not parse endpoints for replica {replica.Id}."); } // TODO: FabricServiceEndpoint has some other fields we are ignoring here. Decide which ones are relevant and fix this call. var serviceEndpoint = new FabricServiceEndpoint( listenerNames: new[] { listenerName }, allowedSchemePredicate: HttpsSchemeSelector, emptyStringMatchesAnyListener: true); if (!FabricServiceEndpointSelector.TryGetEndpoint(serviceEndpoint, serviceEndpointCollection, out var endpointUri)) { throw new ConfigException($"No acceptable endpoints found for replica '{replica.Id}'. Search criteria: listenerName='{listenerName}', emptyStringMatchesAnyListener=true."); } // Get service endpoint from the health listener, health listener is optional. Uri healthEndpointUri = null; if (!string.IsNullOrEmpty(healthListenerName)) { var healthEndpoint = new FabricServiceEndpoint( listenerNames: new[] { healthListenerName }, allowedSchemePredicate: HttpsSchemeSelector, emptyStringMatchesAnyListener: true); if (!FabricServiceEndpointSelector.TryGetEndpoint(healthEndpoint, serviceEndpointCollection, out healthEndpointUri)) { throw new ConfigException($"No acceptable health endpoints found for replica '{replica.Id}'. Search criteria: listenerName='{healthListenerName}', emptyStringMatchesAnyListener=true."); } } return new DestinationConfig { Address = endpointUri.AbsoluteUri, Health = healthEndpointUri?.AbsoluteUri, Metadata = new Dictionary<string, string> { { "PartitionId", partition.Id.ToString() ?? string.Empty }, { "NamedPartitionName", partition.Name ?? string.Empty }, { "ReplicaId", replica.Id.ToString() ?? string.Empty } } }; }
private void listBox1_Click(object sender, EventArgs e) { //Comment one of the URLs //Uri uri = new Uri("http://localhost:8000/EmployeeService?wsdl"); //Uri uri = new Uri("http://Localhost/EmployeeServiceHostWeb/EmployeeServicerHost.svc?wsdl"); Uri uri = new Uri(textBox1.Text); ServiceEndpointCollection endpts = MetadataResolver.Resolve(typeof(IEmployeeService), uri, MetadataExchangeClientMode.HttpGet); foreach (ServiceEndpoint obj in endpts) { IEmployeeService proxy = new ChannelFactory <IEmployeeService>(obj.Binding, obj.Address).CreateChannel(); Employee emp = proxy.GetEmployee(int.Parse(listBox1.SelectedValue.ToString())); label5.Text = emp.EmployeeID.ToString(); label6.Text = emp.FirstName; label7.Text = emp.LastName; ((IChannel)proxy).Close(); } }
internal StatelessServiceInstanceAdapter( StatelessServiceContext context, IStatelessUserServiceInstance userServiceInstance) { this.serviceContext = context; this.traceId = ServiceTrace.GetTraceIdForReplica(context.PartitionId, context.InstanceId); this.serviceHelper = new ServiceHelper(TraceType, this.traceId); this.servicePartition = null; this.instanceListeners = null; this.communicationListeners = null; this.endpointCollection = new ServiceEndpointCollection(); this.runAsynCancellationTokenSource = null; this.executeRunAsyncTask = null; this.userServiceInstance = userServiceInstance; this.userServiceInstance.Addresses = this.endpointCollection.ToReadOnlyDictionary(); }
private static ServiceEndpointCollection ImportEndpoints(MetadataSet metadataSet, IEnumerable<ContractDescription> contracts, MetadataExchangeClient client) { ServiceEndpointCollection endpoints = new ServiceEndpointCollection(); WsdlImporter importer = new WsdlImporter(metadataSet); // remember the original proxy so user doesn't need to set it again importer.State.Add(MetadataExchangeClient.MetadataExchangeClientKey, client); foreach (ContractDescription cd in contracts) { importer.KnownContracts.Add(WsdlExporter.WsdlNamingHelper.GetPortTypeQName(cd), cd); } foreach (ContractDescription cd in contracts) { ServiceEndpointCollection contractEndpoints; contractEndpoints = importer.ImportEndpoints(cd); foreach (ServiceEndpoint se in contractEndpoints) { endpoints.Add(se); } } //Trace all warnings and errors if (importer.Errors.Count > 0) { TraceWsdlImportErrors(importer); } return endpoints; }
private void GenerateConfig( ServiceContractGenerator contractGenerator, ServiceEndpointCollection endpoints) { List<string> addedEndpoints = new List<string>(); foreach (ServiceEndpoint endpoint in endpoints) { // filter by endpoint address so we generate only the endpoint // that matches the endpoint names in ImportedEndpointNames if (!addedEndpoints.Contains(endpoint.Name) && (options.ImportedEndpointNames.Count == 0 || options.ImportedEndpointNames.Contains(endpoint.Name))) { // generate service endpoint ChannelEndpointElement channelElement; contractGenerator.GenerateServiceEndpoint(endpoint, out channelElement); this.generatedChannelElements.Add(channelElement); // generate the binding string bindingSectionName; string configurationName; contractGenerator.GenerateBinding(endpoint.Binding, out bindingSectionName, out configurationName); ThrowOnMetadataConversionErrors(contractGenerator.Errors); addedEndpoints.Add(endpoint.Name); } } // Save changes if specified. if (!string.IsNullOrEmpty(options.OutputConfigurationFile)) { configuration.Save(ConfigurationSaveMode.Modified); } }
public override ServiceEndpointCollection ImportAllEndpoints () { if (endpoint_colln != null) return endpoint_colln; endpoint_colln = new ServiceEndpointCollection (); foreach (WSServiceDescription wsd in wsdl_documents) { foreach (Service service in wsd.Services) { foreach (Port port in service.Ports) { var sep = ImportEndpoint (port, false); if (sep != null) endpoint_colln.Add (sep); } } } return endpoint_colln; }
void ProcessMetaData(ServiceEndpointCollection endpoints) { if(endpoints.Count == 0) { m_Root = new ServiceNode(this,"Service has no endpoints",ServiceIndex,ServiceIndex); m_MexTree.Nodes.Add(m_Root); return; } else { m_Root = new ServiceNode(this,"Exploring...",ServiceIndex,ServiceIndex); m_MexTree.Nodes.Add(m_Root); } int index = 1; foreach(ServiceEndpoint endpoint in endpoints) { AddEndPoint(endpoint,"Endpoint"+index); index++; } DisplayServiceControl(); }
private static ServiceEndpointCollection ResolveContracts ( IEnumerable<ContractDescription> contracts, Func<MetadataSet> metadataGetter) { if (contracts == null) throw new ArgumentNullException ("contracts"); List<ContractDescription> list = new List<ContractDescription> (contracts); if (list.Count == 0) throw new ArgumentException ("There must be atleast one ContractDescription", "contracts"); MetadataSet metadata = metadataGetter (); WsdlImporter importer = new WsdlImporter (metadata); ServiceEndpointCollection endpoints = importer.ImportAllEndpoints (); ServiceEndpointCollection ret = new ServiceEndpointCollection (); foreach (ContractDescription contract in list) { Collection<ServiceEndpoint> colln = endpoints.FindAll (new QName (contract.Name, contract.Namespace)); for (int i = 0; i < colln.Count; i ++) ret.Add (colln [i]); } return ret; }
void ImportEndpoints (ServiceEndpointCollection coll, WSBinding binding) { foreach (WSServiceDescription wsd in wsdl_documents) { foreach (WS.Service service in wsd.Services) { foreach (WS.Port port in service.Ports) { if (!binding.Name.Equals (port.Binding.Name)) continue; var sep = ImportEndpoint (port, false); if (sep != null) coll.Add (sep); } } } }
public ServiceEndpointCollection ImportEndpoints (WSBinding binding) { var coll = new ServiceEndpointCollection (); ImportEndpoints (coll, binding); return coll; }
void AddCompatibleFederationEndpoints(ServiceEndpointCollection serviceEndpoints, IssuedSecurityTokenParameters parameters) { // check if an explicit issuer address has been specified. If so,add the endpoint corresponding to that address only. If not add all acceptable endpoints. bool isIssuerSpecified = (parameters.IssuerAddress != null && !parameters.IssuerAddress.IsAnonymous); foreach (ServiceEndpoint endpoint in serviceEndpoints) { TrustDriver trustDriver; if (!TryGetTrustDriver(endpoint, out trustDriver)) { // if endpoint does not have trustDriver, assume // parent trustDriver. trustDriver = this.trustDriver; } bool isFederationContract = false; ContractDescription contract = endpoint.Contract; for (int j = 0; j < contract.Operations.Count; ++j) { OperationDescription operation = contract.Operations[j]; bool hasIncomingRst = false; bool hasOutgoingRstr = false; for (int k = 0; k < operation.Messages.Count; ++k) { MessageDescription message = operation.Messages[k]; if (message.Action == trustDriver.RequestSecurityTokenAction.Value && message.Direction == MessageDirection.Input) { hasIncomingRst = true; } else if ((((trustDriver.StandardsManager.TrustVersion == TrustVersion.WSTrustFeb2005) && (message.Action == trustDriver.RequestSecurityTokenResponseAction.Value)) || ((trustDriver.StandardsManager.TrustVersion == TrustVersion.WSTrust13) && (message.Action == trustDriver.RequestSecurityTokenResponseFinalAction.Value))) && message.Direction == MessageDirection.Output) { hasOutgoingRstr = true; } } if (hasIncomingRst && hasOutgoingRstr) { isFederationContract = true; break; } } if (isFederationContract) { // skip if it is not an acceptable endpoint if (isIssuerSpecified && !parameters.IssuerAddress.Uri.Equals(endpoint.Address.Uri)) { continue; } if (parameters.IssuerBinding == null) { parameters.IssuerAddress = endpoint.Address; parameters.IssuerBinding = endpoint.Binding; } else { IssuedSecurityTokenParameters.AlternativeIssuerEndpoint endpointInfo = new IssuedSecurityTokenParameters.AlternativeIssuerEndpoint(); endpointInfo.IssuerAddress = endpoint.Address; endpointInfo.IssuerBinding = endpoint.Binding; parameters.AlternativeIssuerEndpoints.Add(endpointInfo); } } } }
private static ServiceEndpointCollection ImportEndpoints(MetadataSet metadataSet, IEnumerable<ContractDescription> contracts, MetadataExchangeClient client) { ServiceEndpointCollection endpoints = new ServiceEndpointCollection(); WsdlImporter importer = new WsdlImporter(metadataSet); importer.State.Add("MetadataExchangeClientKey", client); foreach (ContractDescription description in contracts) { importer.KnownContracts.Add(WsdlExporter.WsdlNamingHelper.GetPortTypeQName(description), description); } foreach (ContractDescription description2 in contracts) { foreach (ServiceEndpoint endpoint in importer.ImportEndpoints(description2)) { endpoints.Add(endpoint); } } if (importer.Errors.Count > 0) { TraceWsdlImportErrors(importer); } return endpoints; }
public ServiceEndpointCollection ImportEndpoints (PortType portType) { var coll = new ServiceEndpointCollection (); foreach (WSServiceDescription wsd in wsdl_documents) { foreach (WS.Binding binding in wsd.Bindings) { if (!binding.Type.Name.Equals (portType.Name)) continue; ImportEndpoints (coll, binding); } } return coll; }
private void HandleResult(IAsyncResult result) { MetadataSet metadataSet = this.client.EndGetMetadata(result); this.endpointCollection = MetadataResolver.ImportEndpoints(metadataSet, this.knownContracts, this.client); }
public ServiceEndpointCollection ImportEndpoints (Service service) { var coll = new ServiceEndpointCollection (); foreach (Port port in service.Ports) { var sep = ImportEndpoint (port, false); if (sep != null) coll.Add (sep); } return coll; }
void ProcessMetaData(ServiceNode existingNode,string mexAddress,ServiceEndpointCollection endpoints) { ProcessMetaData(existingNode,mexAddress,endpoints.ToArray()); }
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); }
public override ServiceEndpointCollection ImportAllEndpoints () { if (endpoint_colln != null) return endpoint_colln; endpoint_colln = new ServiceEndpointCollection (); foreach (IWsdlImportExtension extension in wsdl_extensions) { extension.BeforeImport (wsdl_documents, xmlschemas, policies); } foreach (WSServiceDescription wsd in wsdl_documents) foreach (Service service in wsd.Services) foreach (Port port in service.Ports) endpoint_colln.Add (ImportEndpoint (port)); return endpoint_colln; }
public ServiceDescription() { this.behaviors = new KeyedByTypeCollection<IServiceBehavior>(); this.endpoints = new ServiceEndpointCollection(); this.serviceNamespace = "http://tempuri.org/"; }
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; } }
private void CheckIEchoServiceEndpoint (ServiceEndpointCollection endpoints) { Assert.IsNotNull (endpoints); Assert.AreEqual (1, endpoints.Count); ServiceEndpoint ep = endpoints [0]; //URI Dependent //Assert.AreEqual ("http://localhost:8080/echo/svc", ep.Address.Uri.AbsoluteUri, "#R1"); Assert.AreEqual ("IEchoService", ep.Contract.Name, "#R3"); Assert.AreEqual ("http://myns/echo", ep.Contract.Namespace, "#R4"); Assert.AreEqual ("BasicHttpBinding_IEchoService", ep.Name, "#R5"); Assert.AreEqual (typeof (BasicHttpBinding), ep.Binding.GetType (), "#R2"); }
private void AddCompatibleFederationEndpoints(ServiceEndpointCollection serviceEndpoints, IssuedSecurityTokenParameters parameters) { bool flag = (parameters.IssuerAddress != null) && !parameters.IssuerAddress.IsAnonymous; foreach (ServiceEndpoint endpoint in serviceEndpoints) { TrustDriver trustDriver; if (!this.TryGetTrustDriver(endpoint, out trustDriver)) { trustDriver = this.trustDriver; } bool flag2 = false; ContractDescription contract = endpoint.Contract; for (int i = 0; i < contract.Operations.Count; i++) { OperationDescription description2 = contract.Operations[i]; bool flag3 = false; bool flag4 = false; for (int j = 0; j < description2.Messages.Count; j++) { MessageDescription description3 = description2.Messages[j]; if ((description3.Action == trustDriver.RequestSecurityTokenAction.Value) && (description3.Direction == MessageDirection.Input)) { flag3 = true; } else if ((((trustDriver.StandardsManager.TrustVersion == TrustVersion.WSTrustFeb2005) && (description3.Action == trustDriver.RequestSecurityTokenResponseAction.Value)) || ((trustDriver.StandardsManager.TrustVersion == TrustVersion.WSTrust13) && (description3.Action == trustDriver.RequestSecurityTokenResponseFinalAction.Value))) && (description3.Direction == MessageDirection.Output)) { flag4 = true; } } if (flag3 && flag4) { flag2 = true; break; } } if (flag2 && (!flag || parameters.IssuerAddress.Uri.Equals(endpoint.Address.Uri))) { if (parameters.IssuerBinding == null) { parameters.IssuerAddress = endpoint.Address; parameters.IssuerBinding = endpoint.Binding; } else { IssuedSecurityTokenParameters.AlternativeIssuerEndpoint item = new IssuedSecurityTokenParameters.AlternativeIssuerEndpoint { IssuerAddress = endpoint.Address, IssuerBinding = endpoint.Binding }; parameters.AlternativeIssuerEndpoints.Add(item); } } } }