private void SetupMachineName()
 {
     if (this._forcedMachineName != null)
     {
         this._machineName = CoreChannel.DecodeMachineName(this._forcedMachineName);
     }
     else if (!this._bUseIpAddress)
     {
         this._machineName = CoreChannel.GetMachineName();
     }
     else
     {
         if ((this._bindToAddr == IPAddress.Any) || (this._bindToAddr == IPAddress.IPv6Any))
         {
             this._machineName = CoreChannel.GetMachineIp();
         }
         else
         {
             this._machineName = this._bindToAddr.ToString();
         }
         if (this._bindToAddr.AddressFamily == AddressFamily.InterNetworkV6)
         {
             this._machineName = "[" + this._machineName + "]";
         }
     }
 }
Exemple #2
0
        } // HttpServerChannel

        private void SetupMachineName()
        {
            if (_forcedMachineName != null)
            {
                // an explicitly configured machine name was used
                _machineName = CoreChannel.DecodeMachineName(_forcedMachineName);
            }
            else
            {
                if (!_bUseIpAddress)
                {
                    _machineName = CoreChannel.GetMachineName();
                }
                else
                {
                    if (_bindToAddr == IPAddress.Any)
                    {
                        _machineName = CoreChannel.GetMachineIp();
                    }
                    else
                    {
                        _machineName = _bindToAddr.ToString();
                    }
                }
            }
        } // SetupMachineName
        private void SetupMachineName()
        {
            if (_forcedMachineName != null)
            {
                // an explicitly configured machine name was used
                _machineName = CoreChannel.DecodeMachineName(_forcedMachineName);
            }
            else
            {
                if (!_bUseIpAddress)
                {
                    _machineName = CoreChannel.GetMachineName();
                }
                else
                {
                    if (_bindToAddr == IPAddress.Any || _bindToAddr == IPAddress.IPv6Any)
                    {
                        _machineName = CoreChannel.GetMachineIp();
                    }
                    else
                    {
                        _machineName = _bindToAddr.ToString();
                    }

                    // Add [] around the ipadress for IPv6
                    if (_bindToAddr.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        _machineName = "[" + _machineName + "]";
                    }
                }
            }
        } // SetupMachineName
 private static string SetupUrlBashingForIisIfNecessaryWorker(string hostName)
 {
     string str = null;
     HttpContext current = HttpContext.Current;
     if (current == null)
     {
         return str;
     }
     HttpRequest request = current.Request;
     string str2 = null;
     if (request.IsSecureConnection)
     {
         str2 = "https";
     }
     else
     {
         str2 = "http";
     }
     int port = current.Request.Url.Port;
     StringBuilder builder = new StringBuilder(100);
     builder.Append(str2);
     builder.Append("://");
     if (hostName != null)
     {
         builder.Append(hostName);
     }
     else
     {
         builder.Append(CoreChannel.GetMachineName());
     }
     builder.Append(":");
     builder.Append(port.ToString(CultureInfo.InvariantCulture));
     return builder.ToString();
 }
        private static string SetupUrlBashingForIisIfNecessaryWorker(string hostName)
        {
            // For IIS, we will [....] the scheme://hostname:port with the incoming value
            String      iisHostOverride = null;
            HttpContext context         = HttpContext.Current;

            if (context != null)
            {
                HttpRequest request = context.Request;
                String      scheme  = null;
                if (request.IsSecureConnection)
                {
                    scheme = "https";
                }
                else
                {
                    scheme = "http";
                }

                int port = context.Request.Url.Port;

                StringBuilder sb = new StringBuilder(100);
                sb.Append(scheme);
                sb.Append("://");
                if (hostName != null)
                {
                    sb.Append(hostName);
                }
                else
                {
                    sb.Append(CoreChannel.GetMachineName());
                }
                sb.Append(":");
                sb.Append(port.ToString(CultureInfo.InvariantCulture));

                iisHostOverride = sb.ToString();
            }

            return(iisHostOverride);
        } // SetupUrlBashingForIisIfNecessaryWorker
Exemple #6
0
        } // ShouldIntercept

        private void GenerateSdl(SdlType sdlType,
                                 IServerResponseChannelSinkStack sinkStack,
                                 ITransportHeaders requestHeaders,
                                 ITransportHeaders responseHeaders,
                                 out Stream outputStream)
        {
            if (!MetadataEnabled)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_MetadataNotEnabled"));
            }

            String requestUri = requestHeaders[CommonTransportKeys.RequestUri] as String;
            String objectUri  = HttpChannelHelper.GetObjectUriFromRequestUri(requestUri);

            if (!RemoteApplicationMetadataEnabled &&
                (String.Compare(objectUri, "RemoteApplicationMetadata.rem", true, CultureInfo.InvariantCulture) == 0))
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_RemoteApplicationMetadataNotEnabled"));
            }

            // If the host header is present, we will use this in the generated uri's
            String hostName = (String)requestHeaders["Host"];

            if (hostName != null)
            {
                // filter out port number if present
                int index = hostName.IndexOf(':');
                if (index != -1)
                {
                    hostName = hostName.Substring(0, index);
                }
            }

            // For IIS, we will bash the scheme://hostname:port with the incoming value
            String      iisHostOverride = null;
            HttpContext context         = HttpContext.Current;

            if (context != null)
            {
                HttpRequest request = context.Request;
                String      scheme  = null;
                if (request.IsSecureConnection)
                {
                    scheme = "https";
                }
                else
                {
                    scheme = "http";
                }

                int port = context.Request.Url.Port;

                StringBuilder sb = new StringBuilder(100);
                sb.Append(scheme);
                sb.Append("://");
                if (hostName != null)
                {
                    sb.Append(hostName);
                }
                else
                {
                    sb.Append(CoreChannel.GetMachineName());
                }
                sb.Append(":");
                sb.Append(port.ToString());

                iisHostOverride = sb.ToString();
            }


            ServiceType[] types = null;

            if (String.Compare(objectUri, "RemoteApplicationMetadata.rem", true, CultureInfo.InvariantCulture) == 0)
            {
                // get the service description for all registered service types

                ActivatedServiceTypeEntry[] activatedTypes =
                    RemotingConfiguration.GetRegisteredActivatedServiceTypes();

                WellKnownServiceTypeEntry[] wellKnownTypes =
                    RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

                // determine total number of types
                int typeCount = 0;

                if (activatedTypes != null)
                {
                    typeCount += activatedTypes.Length;
                }

                if (wellKnownTypes != null)
                {
                    typeCount += wellKnownTypes.Length;
                }

                types = new ServiceType[typeCount];

                // collect data
                int co = 0;
                if (activatedTypes != null)
                {
                    foreach (ActivatedServiceTypeEntry entry in activatedTypes)
                    {
                        types[co++] = new ServiceType(entry.ObjectType, null);
                    }
                }

                if (wellKnownTypes != null)
                {
                    foreach (WellKnownServiceTypeEntry entry in wellKnownTypes)
                    {
                        String[] urls = _receiver.GetUrlsForUri(entry.ObjectUri);
                        String   url  = urls[0];
                        if (iisHostOverride != null)
                        {
                            url = HttpChannelHelper.ReplaceChannelUriWithThisString(url, iisHostOverride);
                        }
                        else
                        if (hostName != null)
                        {
                            url = HttpChannelHelper.ReplaceMachineNameWithThisString(url, hostName);
                        }

                        types[co++] = new ServiceType(entry.ObjectType, url);
                    }
                }

                InternalRemotingServices.RemotingAssert(co == typeCount, "Not all types were processed.");
            }
            else
            {
                // get the service description for a particular object
                Type objectType = RemotingServices.GetServerTypeForUri(objectUri);
                if (objectType == null)
                {
                    throw new RemotingException(
                              String.Format(
                                  "Object with uri '{0}' does not exist at server.",
                                  objectUri));
                }

                String[] urls = _receiver.GetUrlsForUri(objectUri);
                String   url  = urls[0];
                if (iisHostOverride != null)
                {
                    url = HttpChannelHelper.ReplaceChannelUriWithThisString(url, iisHostOverride);
                }
                else
                if (hostName != null)
                {
                    url = HttpChannelHelper.ReplaceMachineNameWithThisString(url, hostName);
                }

                types    = new ServiceType[1];
                types[0] = new ServiceType(objectType, url);
            }

            responseHeaders["Content-Type"] = "text/xml";

            bool bMemStream = false;

            outputStream = sinkStack.GetResponseStream(null, responseHeaders);
            if (outputStream == null)
            {
                outputStream = new MemoryStream(1024);
                bMemStream   = true;
            }

            MetaData.ConvertTypesToSchemaToStream(types, sdlType, outputStream);

            if (bMemStream)
            {
                outputStream.Position = 0;
            }
        } // GenerateXmlForUri