コード例 #1
0
        // helper function used by subclasses
        protected Configuration GetConfigurationFromFile(string fileName)
        {
            ExeConfigurationFileMap fileMap       = new ExeConfigurationFileMap();
            Configuration           machineConfig = ConfigurationManager.OpenMachineConfiguration();

            fileMap.MachineConfigFilename = machineConfig.FilePath;
            fileMap.ExeConfigFilename     = fileName;

            if (!IsValidRuntime(fileName))
            {
                string runtimeVersion = Assembly.GetExecutingAssembly().ImageRuntimeVersion;
                ToolConsole.WriteError(SR.GetString(SR.InvalidRuntime, runtimeVersion), "");
                throw Tool.CreateException(SR.GetString(SR.OperationAbortedDuetoClrVersion), null);
            }

            return(ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None));
        }
コード例 #2
0
        static internal bool VerifyInterface(ComAdminInterfaceInfo interfaceInfo, bool allowReferences, Guid clsid, bool produceError)
        {
            if (IsInternalInterface(interfaceInfo.Iid))
            {
                if (produceError)
                {
                    ToolConsole.WriteError(SR.GetString(SR.IsInternalInterfaceAndCannotBeExposedOverWebService, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name), "");
                }
                else
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.IsInternalInterfaceAndCannotBeExposedOverWebService, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name));
                }

                return(false);
            }
            Type typeOfInterfaceResolver = typeof(Message).Assembly.GetType("System.ServiceModel.ComIntegration.TypeCacheManager");

            object resolver = typeOfInterfaceResolver.InvokeMember("Provider", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty, null, null, null, CultureInfo.InvariantCulture);

            object[] args = new object[1] {
                interfaceInfo.Iid
            };
            Type typeOfInterface = null;

            try
            {
                typeOfInterface = typeOfInterfaceResolver.InvokeMember("VerifyType", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, resolver, args, CultureInfo.InvariantCulture) as Type;
            }
            catch (TargetInvocationException e)
            {
                if (e.GetBaseException() is System.IO.FileNotFoundException)
                {
                    throw CreateDescriptiveException((System.IO.FileNotFoundException)e.GetBaseException());
                }

                string exceptionMessage = SR.GetString(SR.TypeResolutionForInterfaceFailed, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name, e.InnerException.Message);

                if (DerivesFromServicedComponent(interfaceInfo.Iid, clsid))
                {
                    exceptionMessage += " " + SR.GetString(SR.ClassInterfacesNotSupported);
                }

                if (produceError)
                {
                    ToolConsole.WriteError(exceptionMessage, "");
                }
                else
                {
                    ToolConsole.WriteNonVerboseWarning(exceptionMessage);
                }

                return(false);
            }

            MethodInfo[] methods = typeOfInterface.GetMethods();
            if (methods.Length == 0)
            {
                if (produceError)
                {
                    ToolConsole.WriteError(SR.GetString(SR.InterfaceHasNoMethods, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name), "");
                }
                else
                {
                    ToolConsole.WriteNonVerboseWarning(SR.GetString(SR.InterfaceHasNoMethods, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name));
                }

                return(false);
            }
            string typeMismatchDetails;

            foreach (MethodInfo method in methods)
            {
                foreach (ParameterInfo parameter in method.GetParameters())
                {
                    Type typeOfParam = parameter.ParameterType;
                    if (typeOfParam.IsByRef)
                    {
                        typeOfParam = typeOfParam.GetElementType();
                    }

                    if (!IsValidParameter(typeOfParam, parameter, allowReferences, out typeMismatchDetails))
                    {
                        if (produceError)
                        {
                            ToolConsole.WriteError(SR.GetString(SR.ParameterOfMethodInInterfaceHasANonCompliantType, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name, method.Name, parameter.Name, typeMismatchDetails), "");
                        }
                        else
                        {
                            ToolConsole.WriteNonVerboseWarning(SR.GetString(SR.ParameterOfMethodInInterfaceHasANonCompliantType, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name, method.Name, parameter.Name, typeMismatchDetails));
                        }

                        return(false);
                    }
                }
                if (!IsValidParameter(method.ReturnType, method.ReturnTypeCustomAttributes, allowReferences, out typeMismatchDetails))
                {
                    if (produceError)
                    {
                        ToolConsole.WriteError(SR.GetString(SR.InvalidWebServiceReturnValue, method.ReturnType.Name, method.Name, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name, typeMismatchDetails), "");
                    }
                    else
                    {
                        ToolConsole.WriteNonVerboseWarning(SR.GetString(SR.InvalidWebServiceReturnValue, method.ReturnType.Name, method.Name, Tool.Options.ShowGuids ? interfaceInfo.Iid.ToString("B") : interfaceInfo.Name, typeMismatchDetails));
                    }

                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
        public override void Add(IList <EndpointConfig> endpointConfigs)
        {
            ThrowIfClosed();

            Configuration config = GetConfiguration(false); // not read only

            Debug.Assert(config != null, "config != null");

            bool         anyAdded         = false;
            const string systemWebSection = "system.web";

            foreach (EndpointConfig endpointConfig in endpointConfigs)
            {
                Guid appid;
                //verify that we someone did not delete and reinstall the app from underneath us
                if (this.svcFileManager.ResolveClsid(endpointConfig.Clsid, out appid))
                {
                    if (endpointConfig.Appid != appid)
                    {
                        ToolConsole.WriteError(SR.GetString(SR.AppIDsDontMatch), "");
                        return;
                    }
                }
            }

            SystemWebSectionGroup swsg = (SystemWebSectionGroup)config.GetSectionGroup(systemWebSection);
            CompilationSection    compilationSection = swsg.Compilation;

            if (string.IsNullOrEmpty(compilationSection.TargetFramework) && RuntimeVersions.V40 == this.runtimeVersion)
            {
                anyAdded = true;
                compilationSection.TargetFramework = ".NETFramework, Version=v4.0";
            }

            foreach (EndpointConfig endpointConfig in endpointConfigs)
            {
                bool added = this.BaseAddEndpointConfig(config, endpointConfig);
                if (added)
                {
                    this.svcFileManager.Add(endpointConfig.Appid, endpointConfig.Clsid);
                    anyAdded = true;

                    // the metadata exchange endpoint is not displayed as a regular endpoint
                    if (endpointConfig.Iid == typeof(IMetadataExchange).GUID)
                    {
                        ToolConsole.WriteLine(SR.GetString(SR.MexEndpointAdded));
                        continue;
                    }

                    if (!Tool.Options.ShowGuids)
                    {
                        ToolConsole.WriteLine(SR.GetString(SR.InterfaceAdded, endpointConfig.ComponentProgID, endpointConfig.InterfaceName));
                    }
                    else
                    {
                        ToolConsole.WriteLine(SR.GetString(SR.InterfaceAdded, endpointConfig.Clsid, endpointConfig.Iid));
                    }
                }
                else
                {
                    // the metadata exchange endpoint is not displayed as a regular endpoint
                    if (endpointConfig.Iid == typeof(IMetadataExchange).GUID)
                    {
                        if (!Tool.Options.ShowGuids)
                        {
                            ToolConsole.WriteWarning(SR.GetString(SR.MexEndpointAlreadyExposed, endpointConfig.ComponentProgID));
                        }
                        else
                        {
                            ToolConsole.WriteWarning(SR.GetString(SR.MexEndpointAlreadyExposed, endpointConfig.Clsid));
                        }
                    }
                    else
                    {
                        if (!Tool.Options.ShowGuids)
                        {
                            ToolConsole.WriteWarning(SR.GetString(SR.InterfaceAlreadyExposed, endpointConfig.ComponentProgID, endpointConfig.InterfaceName));
                        }
                        else
                        {
                            ToolConsole.WriteWarning(SR.GetString(SR.InterfaceAlreadyExposed, endpointConfig.Clsid, endpointConfig.Iid));
                        }
                    }
                }
            }

            if (anyAdded)
            {
                WasModified = true;
                config.Save();
            }
        }