public void Save([NotNull] XmlTextWriter output) { Assert.ArgumentNotNull(output, nameof(output)); var blowFish = new BlowFish(BlowFish.CipherKey); var encryptedPassword = blowFish.Encrypt_ECB(Password); output.WriteStartElement(@"binding"); output.WriteAttributeString(@"hostName", HostName); output.WriteAttributeString(@"useWindowsAuth", UseWindowsAuth ? @"true" : @"false"); output.WriteAttributeString(@"userName", UserName); output.WriteAttributeString(@"password", encryptedPassword); output.WriteAttributeString(@"dataService", DataServiceName); output.WriteAttributeString(@"webRootPath", WebRootPath); output.WriteAttributeString(@"description", Description); output.WriteAttributeString(@"isRemoteSitecore", IsRemoteSitecore ? @"true" : @"false"); output.WriteAttributeString(@"automaticallyUpdate", AutomaticallyUpdate ? @"true" : @"false"); output.WriteAttributeString(@"isHidden", IsHidden ? @"true" : @"false"); output.WriteAttributeString(@"hostNameComparisonMode", HostNameComparisonMode.ToString()); output.WriteAttributeString(@"receiveTimeout", ReceiveTimeout.ToString()); output.WriteAttributeString(@"sendTimeout", SendTimeout.ToString()); output.WriteAttributeString(@"openTimeout", OpenTimeout.ToString()); output.WriteAttributeString(@"closeTimeout", CloseTimeout.ToString()); output.WriteAttributeString(@"maxReceivedMessageSize", MaxReceivedMessageSize.ToString()); output.WriteAttributeString(@"maxBufferSize", MaxBufferSize.ToString()); output.WriteAttributeString(@"maxBufferPoolSize", MaxBufferPoolSize.ToString()); output.WriteAttributeString(@"maxStringContentLength", MaxStringContentLength.ToString()); output.WriteAttributeString(@"transferMode", TransferMode.ToString()); output.WriteAttributeString(@"messageEncoding", MessageEncoding.ToString()); output.WriteAttributeString(@"textEncoding", TextEncoding.WebName); output.WriteAttributeString(@"bypassProxyOnLocal", BypassProxyOnLocal ? @"true" : @"false"); output.WriteAttributeString(@"useDefaultWebProxy", UseDefaultWebProxy ? @"true" : @"false"); if (ProxyAddress != null) { output.WriteAttributeString(@"proxyAddress", ProxyAddress.ToString()); } else { output.WriteAttributeString(@"proxyAddress", string.Empty); } output.WriteEndElement(); }
internal override void OnOpen() { listener = new HttpListener(); string host; switch (HostNameComparisonMode) { case HostNameComparisonMode.Exact: // Uri.DnsSafeHost strips the [], but preserves the scopeid for IPV6 addresses. if (ListenUri.HostNameType == UriHostNameType.IPv6) { host = string.Concat("[", ListenUri.DnsSafeHost, "]"); } else { host = ListenUri.NormalizedHost(); } break; case HostNameComparisonMode.StrongWildcard: host = "+"; break; case HostNameComparisonMode.WeakWildcard: host = "*"; break; default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.UnrecognizedHostNameComparisonMode, HostNameComparisonMode.ToString()))); } string path = ListenUri.GetComponents(UriComponents.Path, UriFormat.Unescaped); if (!path.StartsWith("/", StringComparison.Ordinal)) { path = "/" + path; } if (!path.EndsWith("/", StringComparison.Ordinal)) { path = path + "/"; } string httpListenUrl = string.Concat(Scheme, "://", host, ":", ListenUri.Port, path); listener.UnsafeConnectionNtlmAuthentication = this.unsafeConnectionNtlmAuthentication; listener.AuthenticationSchemeSelectorDelegate = new AuthenticationSchemeSelector(SelectAuthenticationScheme); if (ExtendedProtectionPolicy.OSSupportsExtendedProtection) { //This API will throw if on an unsupported platform. listener.ExtendedProtectionSelectorDelegate = new HttpListener.ExtendedProtectionSelector(SelectExtendedProtectionPolicy); } if (this.Realm != null) { listener.Realm = this.Realm; } bool success = false; try { listener.Prefixes.Add(httpListenUrl); listener.Start(); bool startedListening = false; try { if (Thread.CurrentThread.IsThreadPoolThread) { StartListening(); } else { // If we're not on a threadpool thread, then we need to post a callback to start our accepting loop // Otherwise if the calling thread aborts then the async I/O will get inadvertantly cancelled listenStartedEvent = new ManualResetEvent(false); ActionItem.Schedule(OnListening, null); listenStartedEvent.WaitOne(); listenStartedEvent.Close(); listenStartedEvent = null; if (listenStartedException != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(listenStartedException); } } startedListening = true; } finally { if (!startedListening) { listener.Stop(); } } success = true; } catch (HttpListenerException listenerException) { switch (listenerException.NativeErrorCode) { case UnsafeNativeMethods.ERROR_ALREADY_EXISTS: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAlreadyInUseException(SR.GetString(SR.HttpRegistrationAlreadyExists, httpListenUrl), listenerException)); case UnsafeNativeMethods.ERROR_SHARING_VIOLATION: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAlreadyInUseException(SR.GetString(SR.HttpRegistrationPortInUse, httpListenUrl, ListenUri.Port), listenerException)); case UnsafeNativeMethods.ERROR_ACCESS_DENIED: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAccessDeniedException(SR.GetString(SR.HttpRegistrationAccessDenied, httpListenUrl), listenerException)); case UnsafeNativeMethods.ERROR_ALLOTTED_SPACE_EXCEEDED: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.HttpRegistrationLimitExceeded, httpListenUrl), listenerException)); case UnsafeNativeMethods.ERROR_INVALID_PARAMETER: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.HttpInvalidListenURI, ListenUri.OriginalString), listenerException)); default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( HttpChannelUtilities.CreateCommunicationException(listenerException)); } } finally { if (!success) { listener.Abort(); } } }