コード例 #1
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", StringComparison.OrdinalIgnoreCase) == 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);
                }
            }



            ServiceType[] types = null;

            if (String.Compare(objectUri, "RemoteApplicationMetadata.rem", StringComparison.OrdinalIgnoreCase) == 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 (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(
                                  CultureInfo.CurrentCulture, "Object with uri '{0}' does not exist at server.",
                                  objectUri));
                }

                String[] urls = _receiver.GetUrlsForUri(objectUri);
                String   url  = urls[0];
                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
コード例 #2
0
 private void GenerateSdl(SdlType sdlType, IServerResponseChannelSinkStack sinkStack, ITransportHeaders requestHeaders, ITransportHeaders responseHeaders, out Stream outputStream)
 {
     if (!this.MetadataEnabled)
     {
         throw new RemotingException(CoreChannel.GetResourceString("Remoting_MetadataNotEnabled"));
     }
     string uri = requestHeaders["__RequestUri"] as string;
     string objectUriFromRequestUri = HttpChannelHelper.GetObjectUriFromRequestUri(uri);
     if (!this.RemoteApplicationMetadataEnabled && (string.Compare(objectUriFromRequestUri, "RemoteApplicationMetadata.rem", StringComparison.OrdinalIgnoreCase) == 0))
     {
         throw new RemotingException(CoreChannel.GetResourceString("Remoting_RemoteApplicationMetadataNotEnabled"));
     }
     string hostName = (string) requestHeaders["Host"];
     if (hostName != null)
     {
         int index = hostName.IndexOf(':');
         if (index != -1)
         {
             hostName = hostName.Substring(0, index);
         }
     }
     string channelUri = SetupUrlBashingForIisIfNecessary(hostName);
     ServiceType[] serviceTypes = null;
     if (string.Compare(objectUriFromRequestUri, "RemoteApplicationMetadata.rem", StringComparison.OrdinalIgnoreCase) == 0)
     {
         ActivatedServiceTypeEntry[] registeredActivatedServiceTypes = RemotingConfiguration.GetRegisteredActivatedServiceTypes();
         WellKnownServiceTypeEntry[] registeredWellKnownServiceTypes = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
         int num2 = 0;
         if (registeredActivatedServiceTypes != null)
         {
             num2 += registeredActivatedServiceTypes.Length;
         }
         if (registeredWellKnownServiceTypes != null)
         {
             num2 += registeredWellKnownServiceTypes.Length;
         }
         serviceTypes = new ServiceType[num2];
         int num3 = 0;
         if (registeredActivatedServiceTypes != null)
         {
             foreach (ActivatedServiceTypeEntry entry in registeredActivatedServiceTypes)
             {
                 serviceTypes[num3++] = new ServiceType(entry.ObjectType, null);
             }
         }
         if (registeredWellKnownServiceTypes != null)
         {
             foreach (WellKnownServiceTypeEntry entry2 in registeredWellKnownServiceTypes)
             {
                 string url = this._receiver.GetUrlsForUri(entry2.ObjectUri)[0];
                 if (channelUri != null)
                 {
                     url = HttpChannelHelper.ReplaceChannelUriWithThisString(url, channelUri);
                 }
                 else if (hostName != null)
                 {
                     url = HttpChannelHelper.ReplaceMachineNameWithThisString(url, hostName);
                 }
                 serviceTypes[num3++] = new ServiceType(entry2.ObjectType, url);
             }
         }
     }
     else
     {
         Type serverTypeForUri = RemotingServices.GetServerTypeForUri(objectUriFromRequestUri);
         if (serverTypeForUri == null)
         {
             throw new RemotingException(string.Format(CultureInfo.CurrentCulture, "Object with uri '{0}' does not exist at server.", new object[] { objectUriFromRequestUri }));
         }
         string str6 = this._receiver.GetUrlsForUri(objectUriFromRequestUri)[0];
         if (channelUri != null)
         {
             str6 = HttpChannelHelper.ReplaceChannelUriWithThisString(str6, channelUri);
         }
         else if (hostName != null)
         {
             str6 = HttpChannelHelper.ReplaceMachineNameWithThisString(str6, hostName);
         }
         serviceTypes = new ServiceType[] { new ServiceType(serverTypeForUri, str6) };
     }
     responseHeaders["Content-Type"] = "text/xml";
     bool flag = false;
     outputStream = sinkStack.GetResponseStream(null, responseHeaders);
     if (outputStream == null)
     {
         outputStream = new MemoryStream(0x400);
         flag = true;
     }
     MetaData.ConvertTypesToSchemaToStream(serviceTypes, sdlType, outputStream);
     if (flag)
     {
         outputStream.Position = 0L;
     }
 }