EndpointDispatcher(EndpointDispatcher baseEndpoint, IEnumerable<AddressHeader> headers) { EndpointAddressBuilder builder = new EndpointAddressBuilder(baseEndpoint.EndpointAddress); foreach (AddressHeader h in headers) { builder.Headers.Add(h); } EndpointAddress address = builder.ToEndpointAddress(); this.addressFilter = new EndpointAddressMessageFilter(address); // channelDispatcher is Attached this.contractFilter = baseEndpoint.ContractFilter; this.contractName = baseEndpoint.ContractName; this.contractNamespace = baseEndpoint.ContractNamespace; this.dispatchRuntime = baseEndpoint.DispatchRuntime; // endpointFilter is lazy this.filterPriority = baseEndpoint.FilterPriority + 1; this.originalAddress = address; if (PerformanceCounters.PerformanceCountersEnabled) { this.perfCounterId = baseEndpoint.perfCounterId; this.perfCounterBaseId = baseEndpoint.perfCounterBaseId; } this.id = baseEndpoint.id; }
public SubscriptionManager(EndpointAddressBuilder existingAddressBuilder, string identifier, Uri toUri, string deliveryResourceUri) { existingAddressBuilder.Uri = toUri; existingAddressBuilder.Headers.Add(new IdentifierHeader(identifier)); existingAddressBuilder.Headers.Add(new ResourceUriHeader(deliveryResourceUri)); _address = existingAddressBuilder.ToEndpointAddress(); }
public ExportHelper() { var endpointAddress = Endpoint.Address; EndpointAddressBuilder newEndpointAddress = new EndpointAddressBuilder(endpointAddress); newEndpointAddress.Uri = new Uri(ConfigHelper.GetEndpointAddress()); this.Endpoint.Address = newEndpointAddress.ToEndpointAddress(); }
public EndpointAddress CreateEndpointReference(AddressHeader refParam) { if (this.baseEndpoint == null) { DiagnosticUtility.FailFast("Uninitialized base endpoint reference"); } EndpointAddressBuilder builder = new EndpointAddressBuilder(this.baseEndpoint); builder.Headers.Clear(); builder.Headers.Add(refParam); return builder.ToEndpointAddress(); }
public static EndpointAddress ToEndointAddress (ManagementBaseObject obj, bool isLocal) { EndpointAddressBuilder builder = new EndpointAddressBuilder(); builder.Identity = new X509CertificateEndpointIdentity (new X509Certificate2 ("powershell.pfx", "mono")); foreach(var header in GetAddressHeaders(obj, isLocal)) { builder.Headers.Add (header); } builder.Uri = new Uri(CimNamespaces.CimNamespace + "/" + obj.ClassPath.ClassName); return builder.ToEndpointAddress (); }
static void Main() { // Create a client. HelloClient client = new HelloClient(); // Add a reference-parameter header to the address. // Since the EndpointAddress class is immutable, we must use // EndpointAddressBuilder to change the value. EndpointAddressBuilder builder = new EndpointAddressBuilder(client.Endpoint.Address); AddressHeader header = AddressHeader.CreateAddressHeader(IDName, IDNamespace, "John"); builder.Headers.Add(header); client.Endpoint.Address = builder.ToEndpointAddress(); // Call the Hello service operation. Console.WriteLine(client.Hello()); //Closing the client gracefully closes the connection and cleans up resources client.Close(); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }
// Called by OpenAsyncResult public IAsyncResult BeginOpenProxy(EndpointAddress remoteAddress, Binding binding, InstanceContext instanceContext, TimeSpan timeout, AsyncCallback callback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (this.channelFactory != null) Abort(); // to close previously created factory, if any EndpointAddressBuilder meshEprBuilder = new EndpointAddressBuilder(remoteAddress); meshEprBuilder.Uri = config.GetMeshUri(); this.channelFactory = new DuplexChannelFactory<IPeerProxy>(instanceContext, binding, meshEprBuilder.ToEndpointAddress()); this.channelFactory.Endpoint.Behaviors.Add(new ClientViaBehavior(remoteAddress.Uri)); this.channelFactory.Endpoint.Behaviors.Add(new PeerNeighborBehavior(this)); this.channelFactory.Endpoint.Contract.Behaviors.Add(new PeerOperationSelectorBehavior(this.messageHandler)); this.config.SecurityManager.ApplyClientSecurity(channelFactory); this.channelFactory.Open(timeoutHelper.RemainingTime()); this.Proxy = this.channelFactory.CreateChannel(); IAsyncResult result = this.proxyChannel.BeginOpen(timeoutHelper.RemainingTime(), callback, state); if (result.CompletedSynchronously) this.proxyChannel.EndOpen(result); return result; }
public EndpointReference(EndpointAddressBuilder addressBuilder) { _address = addressBuilder.ToEndpointAddress(); }
/// <summary> /// Handles the operation of buying a selected book /// </summary> private void btnBuy_Click(object sender, EventArgs e) { // check if any book is selected for purchase if (lstBooks.SelectedItem == null) { MessageBox.Show("No book selected for purchase", "BookStore Client"); } else { // get the selected book ID string selectedBookItem = lstBooks.SelectedItem.ToString(); int startPos = selectedBookItem.IndexOf('.') + 1; int endPos = selectedBookItem.IndexOf(','); string bookName = selectedBookItem.Substring(startPos, endPos - startPos); bookName = bookName.Trim(); BuyBookClient myBuyBookClient = new BuyBookClient(); try { // Add the book name as a "resource" header to the endpoint address for the service EndpointAddressBuilder myEndpointAddressBuilder = new EndpointAddressBuilder(myBuyBookClient.Endpoint.Address); myEndpointAddressBuilder.Headers.Add(AddressHeader.CreateAddressHeader(Constants.BookNameHeaderName, Constants.BookNameHeaderNamespace, bookName)); myBuyBookClient.Endpoint.Address = myEndpointAddressBuilder.ToEndpointAddress(); // Send the request to the service. This will result in the following steps; // 1. Request a security token from HomeRealmSTS authenticating using Windows credentials // 2. Request a security token from BookStoreSTS authenticating using token from 1. // 3. Send the BuyBook request to the BookStoreService authenticating using token from 2. string response = myBuyBookClient.BuyBook("*****@*****.**", "One Microsoft Way, Redmond, WA 98052"); MessageBox.Show(response, "BookStore Client"); myBuyBookClient.Close(); } catch (Exception ex) { myBuyBookClient.Abort(); // see if a fault has been sent back FaultException inner = GetInnerException(ex) as FaultException; if (inner != null) { MessageFault fault = inner.CreateMessageFault(); MessageBox.Show(String.Format("The server sent back a fault: {0}", fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text)); } else { MessageBox.Show(String.Format("Exception while trying to purchase the selected book: {0}", ex), "BookStore Client"); } } } }
/// <summary> /// Sign this information card and write it to a file. /// </summary> /// <param name="filename">Path to where this card should be stored.</param> /// <param name="cert">Certificate to use for signing this card.</param> public void SerializeAndSign( string filename, X509Certificate2 cert ) { MemoryStream stream = new MemoryStream(); XmlWriter writer = XmlWriter.Create( stream ); writer.WriteStartElement( XmlNames.WSIdentity.InfoCardElement, XmlNames.WSIdentity.Namespace ); // // write the InformationCardReference element // writer.WriteAttributeString( XmlNames.Xml.Language, XmlNames.Xml.Namespace, m_language ); writer.WriteStartElement( XmlNames.WSIdentity.InfoCardRefElement, XmlNames.WSIdentity.Namespace ); writer.WriteElementString( XmlNames.WSIdentity.CardIdElement, XmlNames.WSIdentity.Namespace, m_cardId ); writer.WriteElementString( XmlNames.WSIdentity.CardVersionElement, XmlNames.WSIdentity.Namespace, m_cardVersion ); writer.WriteEndElement(); // // card name // if( !String.IsNullOrEmpty( m_cardName ) ) { writer.WriteStartElement( XmlNames.WSIdentity.CardNameElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( m_cardName ); writer.WriteEndElement(); } // // card image // if( null != m_logo && 0 != m_logo.Length ) { writer.WriteStartElement( XmlNames.WSIdentity.CardImageElement, XmlNames.WSIdentity.Namespace ); if( !String.IsNullOrEmpty( m_mimeType ) ) { writer.WriteAttributeString( XmlNames.WSIdentity.MimeTypeAttribute, m_mimeType ); } string val = Convert.ToBase64String( m_logo ); writer.WriteString( val ); writer.WriteEndElement(); } // // card issuer uri // writer.WriteStartElement( XmlNames.WSIdentity.IssuerElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( m_issuerId ); writer.WriteEndElement(); // // issue time // writer.WriteStartElement( XmlNames.WSIdentity.TimeIssuedElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( XmlConvert.ToString( m_issuedOn, XmlDateTimeSerializationMode.Utc ) ); writer.WriteEndElement(); // // expiry time // writer.WriteStartElement( XmlNames.WSIdentity.TimeExpiresElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( XmlConvert.ToString( m_expiresOn, XmlDateTimeSerializationMode.Utc ) ); writer.WriteEndElement(); // // Start the tokenservice list // writer.WriteStartElement( XmlNames.WSIdentity.TokenServiceListElement, XmlNames.WSIdentity.Namespace ); EndpointAddressBuilder eprBuilder = new EndpointAddressBuilder(); eprBuilder.Uri = new Uri( m_issuerId ); eprBuilder.Identity = new X509CertificateEndpointIdentity( cert ); if( null != m_mexUri ) { MetadataReference mexRef = new MetadataReference(); mexRef.Address = new EndpointAddress( m_mexUri ); mexRef.AddressVersion = AddressingVersion.WSAddressing10; MetadataSection mexSection = new MetadataSection(); mexSection.Metadata = mexRef; MetadataSet mexSet = new MetadataSet(); mexSet.MetadataSections.Add( mexSection ); MemoryStream memStream = new MemoryStream(); XmlTextWriter writer1 = new XmlTextWriter( memStream, System.Text.Encoding.UTF8 ); mexSet.WriteTo( writer1 ); writer1.Flush(); memStream.Seek( 0, SeekOrigin.Begin ); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader( memStream, XmlDictionaryReaderQuotas.Max ); eprBuilder.SetMetadataReader( reader ); } m_epr = eprBuilder.ToEndpointAddress(); writer.WriteStartElement( XmlNames.WSIdentity.TokenServiceElement, XmlNames.WSIdentity.Namespace ); // // Write the EndPointReference // m_epr.WriteTo( AddressingVersion.WSAddressing10, writer ); // // Write the UserCredential Element // writer.WriteStartElement( XmlNames.WSIdentity.UserCredentialElement, XmlNames.WSIdentity.Namespace ); // // Write the hint // if( !String.IsNullOrEmpty( m_hint ) ) { writer.WriteStartElement( XmlNames.WSIdentity.DisplayCredentialHintElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( m_hint ); writer.WriteEndElement(); } switch( m_cardType ) { case DefaultValues.CardType.UserNamePassword: writer.WriteStartElement( XmlNames.WSIdentity.UserNamePasswordCredentialElement, XmlNames.WSIdentity.Namespace ); if( !string.IsNullOrEmpty( m_credentialIdentifier ) ) { writer.WriteStartElement( XmlNames.WSIdentity.UserNameElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( m_credentialIdentifier ); writer.WriteEndElement(); } writer.WriteEndElement(); break; case DefaultValues.CardType.KerberosAuth: writer.WriteStartElement( XmlNames.WSIdentity.KerberosV5CredentialElement, XmlNames.WSIdentity.Namespace ); writer.WriteEndElement(); break; case DefaultValues.CardType.SelfIssuedAuth: writer.WriteStartElement( XmlNames.WSIdentity.SelfIssuedCredentialElement, XmlNames.WSIdentity.Namespace ); if( !string.IsNullOrEmpty( m_credentialIdentifier ) ) { writer.WriteStartElement( XmlNames.WSIdentity.PrivatePersonalIdentifierElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( m_credentialIdentifier ); writer.WriteEndElement(); } else { throw new InvalidDataException( "No PPID was specified" ); } writer.WriteEndElement(); break; case DefaultValues.CardType.SmartCard: writer.WriteStartElement( XmlNames.WSIdentity.X509V3CredentialElement, XmlNames.WSIdentity.Namespace ); writer.WriteStartElement( XmlNames.XmlDSig.X509DataElement, XmlNames.XmlDSig.Namespace ); if( !string.IsNullOrEmpty( m_credentialIdentifier ) ) { writer.WriteStartElement( XmlNames.WSSecurityExt.KeyIdentifierElement, XmlNames.WSSecurityExt.Namespace ); writer.WriteAttributeString( XmlNames.WSSecurityExt.ValueTypeAttribute, null, XmlNames.WSSecurityExt.Sha1ThumbrpintKeyTypeValue ); writer.WriteString( m_credentialIdentifier ); writer.WriteEndElement(); } else { throw new InvalidDataException( "No thumbprint was specified" ); } writer.WriteEndElement(); writer.WriteEndElement(); break; default: break; } writer.WriteEndElement(); //end of user credential writer.WriteEndElement(); // end of tokenservice writer.WriteEndElement(); //end of tokenservice list // // tokentypes // writer.WriteStartElement( XmlNames.WSIdentity.SupportedTokenTypeListElement, XmlNames.WSIdentity.Namespace ); foreach( string type in m_tokenTypes ) { writer.WriteElementString( XmlNames.WSTrust.TokenType, XmlNames.WSTrust.Namespace, type ); } writer.WriteEndElement(); // // claims // writer.WriteStartElement( XmlNames.WSIdentity.SupportedClaimTypeListElement, XmlNames.WSIdentity.Namespace ); foreach( ClaimInfo clm in m_supportedClaims ) { writer.WriteStartElement( XmlNames.WSIdentity.SupportedClaimTypeElement, XmlNames.WSIdentity.Namespace ); writer.WriteAttributeString( XmlNames.WSIdentity.UriAttribute, clm.Id ); if( !String.IsNullOrEmpty( clm.DisplayTag ) ) { writer.WriteElementString( XmlNames.WSIdentity.DisplayTagElement, XmlNames.WSIdentity.Namespace, clm.DisplayTag ); } if( !String.IsNullOrEmpty( clm.Description ) ) { writer.WriteElementString( XmlNames.WSIdentity.DescriptionElement, XmlNames.WSIdentity.Namespace, clm.Description ); } writer.WriteEndElement(); } writer.WriteEndElement(); // // RequireAppliesTo // if( m_requireAppliesTo ) { writer.WriteElementString( XmlNames.WSIdentity.RequireAppliesToElement, XmlNames.WSIdentity.Namespace, null ); } // // Privacy Notice // if( !String.IsNullOrEmpty( m_privacyNoticeAt ) ) { writer.WriteStartElement( XmlNames.WSIdentity.PrivacyNoticeAtElement, XmlNames.WSIdentity.Namespace ); writer.WriteString( m_privacyNoticeAt ); writer.WriteEndElement(); } writer.WriteEndElement(); writer.Close(); // // Sign the xml content // stream.Position = 0; XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.Load( stream ); SignedXml signed = new SignedXml(); signed.SigningKey = cert.PrivateKey; signed.Signature.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl; Reference reference = new Reference(); reference.Uri = "#_Object_InfoCard"; reference.AddTransform( new XmlDsigExcC14NTransform() ); signed.AddReference( reference ); KeyInfo info = new KeyInfo(); KeyInfoX509Data data = new KeyInfoX509Data( cert, X509IncludeOption.WholeChain ); info.AddClause( data ); signed.KeyInfo = info; DataObject cardData = new DataObject( "_Object_InfoCard", null, null, doc.DocumentElement ); signed.AddObject( cardData ); signed.ComputeSignature(); XmlElement e = signed.GetXml(); XmlTextWriter fileWriter = new XmlTextWriter( filename, Encoding.UTF8 ); e.WriteTo( fileWriter ); fileWriter.Flush(); fileWriter.Close(); }
public static EndpointAddress GetIPEndpointAddress(EndpointAddress epr, IPAddress address) { EndpointAddressBuilder builder = new EndpointAddressBuilder(epr) { Uri = GetIPUri(epr.Uri, address) }; return builder.ToEndpointAddress(); }
private void RunRefresh() { try { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Connecting to CodeFlow service" }); var endpointAddressBuilder = new EndpointAddressBuilder(); endpointAddressBuilder.Uri = new Uri("http://codeflow/Services/ReviewService.svc"); endpointAddressBuilder.Identity = new DnsEndpointIdentity("localhost"); // cache needs to be refreshed DateTime lastRefreshed = DateTime.MinValue; string payloadCache = null; while (true) { if (DateTime.Now.Subtract(lastRefreshed).TotalMinutes > this.refreshInterval) { // try up to 3 times for (var retries = 0; retries < 3; retries++) { try { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Loading stats." }); // get a reference to the team project collection using (var reviewServiceClient = new ReviewServiceClient(new WSHttpBinding(), endpointAddressBuilder.ToEndpointAddress())) { reviewServiceClient.Open(); var authorAssignedCount = reviewServiceClient.GetActiveReviewsForReviewer(this.authorWatch).Where(p => DateTime.Now.Subtract(p.LastUpdatedOn).TotalDays <= 7).Count(); var authorCreatedCount = reviewServiceClient.GetActiveReviewsForAuthor(this.authorWatch).Where(p => DateTime.Now.Subtract(p.LastUpdatedOn).TotalDays <= 7).Count(); var authorAssignedIndirectCount = reviewServiceClient.GetActiveReviewsForReviewer(this.secondAuthorWatch).Where(p => DateTime.Now.Subtract(p.LastUpdatedOn).TotalDays <= 7).Count(); payloadCache = string.Format( "{0} {1,-20}{3,-20}{2,-20}{4,-20}", (char)PacketDataType.Text, "CodeFlow Dashboard", "for " + this.authorWatch + ": " + authorAssignedCount, "by " + this.authorWatch + ": " + authorCreatedCount, "for " + this.secondAuthorWatch + ": " + authorAssignedIndirectCount); } this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Built stats: " + payloadCache }); } catch (Exception ex) { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Failed to refresh: " + ex.Message }); continue; } lastRefreshed = DateTime.Now; this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Cached result." }); break; } } else { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Reloading cached." }); } this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Broadcast result: " + payloadCache }); this.publishEvent.Publish(payloadCache); // sleep i said Thread.Sleep(this.announceInterval); } } catch (Exception ex) { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Failure: " + ex.Message }); } }
public void GetListenAddressAndContext(out EndpointAddress listenAddress, out IDictionary<string, string> context) { if (this.CallbackAddress == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackaddress"); } EndpointAddressBuilder builder = new EndpointAddressBuilder(this.CallbackAddress); AddressHeader header = null; int index = -1; for (int i = 0; i < builder.Headers.Count; i++) { if ((builder.Headers[i].Name == "Context") && (builder.Headers[i].Namespace == "http://schemas.microsoft.com/ws/2006/05/context")) { if (header != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MultipleContextHeadersFoundInCallbackAddress"))); } header = builder.Headers[i]; index = i; } } if (header != null) { builder.Headers.RemoveAt(index); } context = (header != null) ? ContextMessageHeader.ParseContextHeader(header.GetAddressHeaderReader()).Context : null; listenAddress = builder.ToEndpointAddress(); }
private static EndpointAddress CreateCallbackAddress(EndpointAddress listenAddress, IDictionary<string, string> context) { if (listenAddress == null) { return null; } EndpointAddressBuilder builder = new EndpointAddressBuilder(listenAddress); if (context != null) { builder.Headers.Add(new ContextAddressHeader(context)); } return builder.ToEndpointAddress(); }
private static AnalyticsSoapClient GetClient() { EndpointAddressBuilder eb = new EndpointAddressBuilder(); eb.Uri = new Uri(address); return new AnalyticsSoapClient(new BasicHttpBinding(), eb.ToEndpointAddress()); }
public FacilityBookingsHelper() { var endpointAddress = Endpoint.Address; EndpointAddressBuilder newEndpointAddress = new EndpointAddressBuilder(endpointAddress); newEndpointAddress.Uri = new Uri(ConfigHelper.GetEndpointAddress()); this.Endpoint.Address = newEndpointAddress.ToEndpointAddress(); }