public void ProcessClientTlb(string ProgId, string SrcTlbPath, string PhysicalPath, string VRoot, string BaseUrl, string Mode, string Transport, out string AssemblyName, out string TypeName, out string Error)
 {
     AssemblyName = "";
     TypeName     = "";
     Error        = "";
     try
     {
         new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
         string clientPhysicalPath = GetClientPhysicalPath(true);
         if (!SrcTlbPath.ToLower(CultureInfo.InvariantCulture).EndsWith("mscoree.dll", StringComparison.Ordinal) && (SrcTlbPath.Length > 0))
         {
             AssemblyName = new GenerateMetadata().Generate(SrcTlbPath, clientPhysicalPath);
             if (ProgId.Length > 0)
             {
                 TypeName = this.GetTypeNameFromProgId(clientPhysicalPath + AssemblyName + ".dll", ProgId);
             }
         }
         else if (ProgId.Length > 0)
         {
             string      g    = (string)Registry.ClassesRoot.OpenSubKey(ProgId + @"\CLSID").GetValue("");
             RegistryKey key2 = Registry.ClassesRoot.OpenSubKey(@"CLSID\{" + new Guid(g) + @"}\InprocServer32");
             AssemblyName = (string)key2.GetValue("Assembly");
             int index = AssemblyName.IndexOf(",");
             if (index > 0)
             {
                 AssemblyName = AssemblyName.Substring(0, index);
             }
             TypeName = (string)key2.GetValue("Class");
         }
         if (ProgId.Length > 0)
         {
             Uri baseUri = new Uri(BaseUrl);
             Uri uri2    = new Uri(baseUri, VRoot);
             if (uri2.Scheme.ToLower(CultureInfo.InvariantCulture) == "https")
             {
                 string authentication = "Windows";
                 SoapClientConfig.Write(clientPhysicalPath, uri2.AbsoluteUri, AssemblyName, TypeName, ProgId, authentication);
             }
             else
             {
                 ClientRemotingConfig.Write(clientPhysicalPath, VRoot, BaseUrl, AssemblyName, TypeName, ProgId, Mode, Transport);
             }
         }
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         Error = exception.ToString();
         ComSoapPublishError.Report(Error);
     }
 }
        public void DeleteServerTlb(string progId, string classId, string interfaceId, string srcTlbPath, string rootWebServer, string baseUrl, string virtualRoot, string operation, string assemblyName, string typeName)
        {
            try
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
            }
            catch (SecurityException)
            {
                ComSoapPublishError.Report(Resource.FormatString("Soap_SecurityFailure"));
                throw;
            }
            string name = assemblyName;

            if ((((progId.Length > 0) || (classId.Length > 0)) || ((assemblyName.Length > 0) || (typeName.Length > 0))) && ((baseUrl.Length > 0) || (virtualRoot.Length > 0)))
            {
                string str3 = SoapServerInfo.ServerPhysicalPath(rootWebServer, baseUrl, virtualRoot, false);
                string str4 = srcTlbPath.ToLower(CultureInfo.InvariantCulture);
                if (!str4.EndsWith("scrobj.dll", StringComparison.Ordinal))
                {
                    if (str4.EndsWith("mscoree.dll", StringComparison.Ordinal))
                    {
                        Type typeFromProgID = Type.GetTypeFromProgID(progId);
                        typeName = typeFromProgID.FullName;
                        name     = typeFromProgID.Assembly.GetName().Name;
                    }
                    else
                    {
                        name = new GenerateMetadata().GetAssemblyName(srcTlbPath, str3 + @"\bin\");
                        if (name.Length > 0)
                        {
                            try
                            {
                                typeName = this.GetTypeName(str3 + @"\bin\" + name + ".dll", progId, classId);
                            }
                            catch (DirectoryNotFoundException)
                            {
                            }
                            catch (FileNotFoundException)
                            {
                            }
                        }
                    }
                    if ((!string.IsNullOrEmpty(progId) && !string.IsNullOrEmpty(name)) && !string.IsNullOrEmpty(typeName))
                    {
                        DiscoFile file         = new DiscoFile();
                        string    assemblyFile = str3 + @"\bin\" + name + ".dll";
                        SoapServerConfig.DeleteComponent(str3 + @"\Web.Config", name, typeName, progId, assemblyFile);
                        file.DeleteElement(str3 + @"\Default.disco", progId + ".soap?WSDL");
                    }
                }
            }
        }
Exemplo n.º 3
0
            public Assembly ResolveRef(object TypeLib)
            {
                Assembly assembly = null;
                IntPtr   zero     = IntPtr.Zero;

                try
                {
                    ((ITypeLib)TypeLib).GetLibAttr(out zero);
                    System.Runtime.InteropServices.ComTypes.TYPELIBATTR typelibattr = (System.Runtime.InteropServices.ComTypes.TYPELIBATTR)Marshal.PtrToStructure(zero, typeof(System.Runtime.InteropServices.ComTypes.TYPELIBATTR));
                    string guidAttr      = typelibattr.guid.ToString(string.Empty, CultureInfo.InvariantCulture);
                    string strMajorVer   = typelibattr.wMajorVerNum.ToString(CultureInfo.InvariantCulture);
                    string strSrcTypeLib = this.GetTlbPath(guidAttr, strMajorVer, typelibattr.wMinorVerNum.ToString(CultureInfo.InvariantCulture));
                    if (strSrcTypeLib.Length > 0)
                    {
                        GenerateMetadata metadata       = new GenerateMetadata();
                        string           error          = "";
                        string           assemblyString = metadata.GenerateSigned(strSrcTypeLib, this.m_strOutputDir, true, out error);
                        if (assemblyString.Length > 0)
                        {
                            assembly = Assembly.Load(assemblyString);
                        }
                    }
                }
                finally
                {
                    if (zero != IntPtr.Zero)
                    {
                        ((ITypeLib)TypeLib).ReleaseTLibAttr(zero);
                    }
                }
                if (null == assembly)
                {
                    ComSoapPublishError.Report(Resource.FormatString("Soap_ResolutionForTypeLibFailed") + " " + Marshal.GetTypeLibName((ITypeLib)TypeLib));
                }
                return(assembly);
            }
        public void ProcessServerTlb(string ProgId, string SrcTlbPath, string PhysicalPath, string Operation, out string strAssemblyName, out string TypeName, out string Error)
        {
            string name = string.Empty;

            strAssemblyName = string.Empty;
            TypeName        = string.Empty;
            Error           = string.Empty;
            bool flag = false;

            try
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                if ((Operation != null) && (Operation.ToLower(CultureInfo.InvariantCulture) == "delete"))
                {
                    flag = true;
                }
                if (SrcTlbPath.Length > 0)
                {
                    if (!PhysicalPath.EndsWith("/", StringComparison.Ordinal) && !PhysicalPath.EndsWith(@"\", StringComparison.Ordinal))
                    {
                        PhysicalPath = PhysicalPath + @"\";
                    }
                    string str2 = SrcTlbPath.ToLower(CultureInfo.InvariantCulture);
                    if (str2.EndsWith("mscoree.dll", StringComparison.Ordinal))
                    {
                        Type typeFromProgID = Type.GetTypeFromProgID(ProgId);
                        if (typeFromProgID.FullName == "System.__ComObject")
                        {
                            throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_DependencyNotInGAC"));
                        }
                        TypeName = typeFromProgID.FullName;
                        name     = typeFromProgID.Assembly.GetName().Name;
                    }
                    else if (str2.EndsWith("scrobj.dll", StringComparison.Ordinal))
                    {
                        if (!flag)
                        {
                            throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_WSCNotSupported"));
                        }
                    }
                    else
                    {
                        GenerateMetadata metadata = new GenerateMetadata();
                        if (flag)
                        {
                            name = metadata.GetAssemblyName(SrcTlbPath, PhysicalPath + @"bin\");
                        }
                        else
                        {
                            name = metadata.GenerateSigned(SrcTlbPath, PhysicalPath + @"bin\", false, out Error);
                        }
                        if (!string.IsNullOrEmpty(name))
                        {
                            try
                            {
                                TypeName = this.GetTypeNameFromProgId(PhysicalPath + @"bin\" + name + ".dll", ProgId);
                            }
                            catch (DirectoryNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                            catch (FileNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    if ((!string.IsNullOrEmpty(ProgId) && !string.IsNullOrEmpty(name)) && !string.IsNullOrEmpty(TypeName))
                    {
                        ServerWebConfig config       = new ServerWebConfig();
                        DiscoFile       file         = new DiscoFile();
                        string          assemblyFile = PhysicalPath + @"bin\" + name + ".dll";
                        if (flag)
                        {
                            config.DeleteElement(PhysicalPath + "Web.Config", name, TypeName, ProgId, "SingleCall", assemblyFile);
                            file.DeleteElement(PhysicalPath + "Default.disco", ProgId + ".soap?WSDL");
                        }
                        else
                        {
                            config.AddGacElement(PhysicalPath + "Web.Config", name, TypeName, ProgId, "SingleCall", assemblyFile);
                            file.AddElement(PhysicalPath + "Default.disco", ProgId + ".soap?WSDL");
                        }
                    }
                    if (!string.IsNullOrEmpty(name))
                    {
                        string fileName = PhysicalPath + @"bin\" + name + ".dll";
                        strAssemblyName = new AssemblyManager().GetFullName(fileName);
                    }
                }
            }
            catch (Exception exception)
            {
                if ((exception is NullReferenceException) || (exception is SEHException))
                {
                    throw;
                }
                Error = exception.ToString();
                ComSoapPublishError.Report(Error);
                if ((typeof(ServicedComponentException) == exception.GetType()) || (typeof(RegistrationException) == exception.GetType()))
                {
                    throw;
                }
            }
        }
        public void AddServerTlb(string progId, string classId, string interfaceId, string srcTlbPath, string rootWebServer, string inBaseUrl, string inVirtualRoot, string clientActivated, string wellKnown, string discoFile, string operation, out string strAssemblyName, out string typeName)
        {
            string name = string.Empty;

            strAssemblyName = string.Empty;
            typeName        = string.Empty;
            bool flag      = false;
            bool inDefault = false;
            bool flag3     = false;
            bool flag4     = true;

            try
            {
                try
                {
                    new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                }
                catch (SecurityException)
                {
                    ComSoapPublishError.Report(Resource.FormatString("Soap_SecurityFailure"));
                    throw;
                }
                if ((operation != null) && (operation.ToLower(CultureInfo.InvariantCulture) == "delete"))
                {
                    flag = true;
                }
                if (srcTlbPath.Length > 0)
                {
                    inDefault = SoapServerInfo.BoolFromString(discoFile, inDefault);
                    flag3     = SoapServerInfo.BoolFromString(wellKnown, flag3);
                    flag4     = SoapServerInfo.BoolFromString(clientActivated, flag4);
                    string str3 = SoapServerInfo.ServerPhysicalPath(rootWebServer, inBaseUrl, inVirtualRoot, !flag);
                    string str4 = srcTlbPath.ToLower(CultureInfo.InvariantCulture);
                    if (str4.EndsWith("mscoree.dll", StringComparison.Ordinal))
                    {
                        Type typeFromProgID = Type.GetTypeFromProgID(progId);
                        typeName = typeFromProgID.FullName;
                        name     = typeFromProgID.Assembly.GetName().Name;
                    }
                    else if (str4.EndsWith("scrobj.dll", StringComparison.Ordinal))
                    {
                        if (!flag)
                        {
                            throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_WSCNotSupported"));
                        }
                    }
                    else
                    {
                        string           error    = "";
                        GenerateMetadata metadata = new GenerateMetadata();
                        if (flag)
                        {
                            name = metadata.GetAssemblyName(srcTlbPath, str3 + @"\bin\");
                        }
                        else
                        {
                            name = metadata.GenerateSigned(srcTlbPath, str3 + @"\bin\", false, out error);
                        }
                        if (!string.IsNullOrEmpty(name))
                        {
                            try
                            {
                                typeName = this.GetTypeName(str3 + @"\bin\" + name + ".dll", progId, classId);
                            }
                            catch (DirectoryNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                            catch (FileNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    if ((!string.IsNullOrEmpty(progId) && !string.IsNullOrEmpty(name)) && !string.IsNullOrEmpty(typeName))
                    {
                        DiscoFile file         = new DiscoFile();
                        string    assemblyFile = str3 + @"\bin\" + name + ".dll";
                        if (flag)
                        {
                            SoapServerConfig.DeleteComponent(str3 + @"\Web.Config", name, typeName, progId, assemblyFile);
                            file.DeleteElement(str3 + @"\Default.disco", progId + ".soap?WSDL");
                        }
                        else
                        {
                            SoapServerConfig.AddComponent(str3 + @"\Web.Config", name, typeName, progId, assemblyFile, "SingleCall", flag3, flag4);
                            if (inDefault)
                            {
                                file.AddElement(str3 + @"\Default.disco", progId + ".soap?WSDL");
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(name))
                    {
                        string fileName = str3 + @"bin\" + name + ".dll";
                        strAssemblyName = new AssemblyManager().GetFullName(fileName);
                    }
                }
            }
            catch (ServicedComponentException exception)
            {
                this.ThrowHelper("Soap_PublishServerTlbFailure", exception);
            }
            catch (RegistrationException exception2)
            {
                this.ThrowHelper("Soap_PublishServerTlbFailure", exception2);
            }
            catch (Exception exception3)
            {
                if ((exception3 is NullReferenceException) || (exception3 is SEHException))
                {
                    throw;
                }
                this.ThrowHelper("Soap_PublishServerTlbFailure", null);
            }
        }
Exemplo n.º 6
0
        /// <include file='doc\SoapServerTlb.uex' path='docs/doc[@for="SoapServerTlb.AddServerTlb"]/*' />
        public void AddServerTlb(
            string progId,
            string classId,
            string interfaceId,
            string srcTlbPath,
            string rootWebServer,
            string inBaseUrl,
            string inVirtualRoot,
            string clientActivated,
            string wellKnown,
            string discoFile,
            string operation,
            out string strAssemblyName,
            out string typeName
            )
        {
            strAssemblyName = "";
            typeName        = "";
            bool bDelete = false;
            //these are the defaults for these flags
            bool bDiscoFile       = false;
            bool bWellKnown       = false;
            bool bClientActivated = true;

            try
            {
                try
                {
                    SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
                    sp.Demand();
                }
                catch (Exception e)
                {
                    if (e.GetType() == typeof(System.Security.SecurityException))
                    {
                        string Error = Resource.FormatString("Soap_SecurityFailure");
                        ComSoapPublishError.Report(Error);
                    }
                    throw;
                }
                Platform.Assert(Platform.Whistler, "SoapServerTlb.AddServerTlb");

                if (null != operation && operation.ToLower(CultureInfo.InvariantCulture) == "delete")
                {
                    bDelete = true;
                }
                //if ProgId is an empty string, it means it does not go in the configuration file
                if (srcTlbPath.Length <= 0)
                {
                    return;
                }
                bDiscoFile       = SoapServerInfo.BoolFromString(discoFile, bDiscoFile);
                bWellKnown       = SoapServerInfo.BoolFromString(wellKnown, bWellKnown);
                bClientActivated = SoapServerInfo.BoolFromString(clientActivated, bClientActivated);
                string PhysicalPath = SoapServerInfo.ServerPhysicalPath(rootWebServer, inBaseUrl, inVirtualRoot, !bDelete);
                string srcdll       = srcTlbPath.ToLower(CultureInfo.InvariantCulture);
                if (srcdll.EndsWith("mscoree.dll"))
                {
                    Type typ = Type.GetTypeFromProgID(progId);
                    typeName = typ.FullName;
                    Assembly     assem     = typ.Assembly;
                    AssemblyName assemname = assem.GetName();
                    strAssemblyName = assemname.Name;
                }
                else if (srcdll.EndsWith("scrobj.dll"))
                {
                    if (!bDelete)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_WSCNotSupported"));
                    }
                }
                else
                {
                    string           Error   = "";
                    GenerateMetadata metaGen = new GenerateMetadata();
                    if (bDelete)
                    {
                        strAssemblyName = metaGen.GetAssemblyName(srcTlbPath, PhysicalPath + "\\bin\\");
                    }
                    else
                    {
                        strAssemblyName = metaGen.GenerateSigned(srcTlbPath, PhysicalPath + "\\bin\\", false, out Error);
                    }
                    if (strAssemblyName.Length > 0)
                    {
                        try
                        {
                            //TODO - review GetTypeNameFromProgId to determine if we can use the IID
                            // to simplify the logic
                            typeName = GetTypeName(PhysicalPath + "\\bin\\" + strAssemblyName + ".dll", progId, classId);
                        }
                        catch (Exception e)
                        {
                            if (bDelete && e.GetType() != typeof(System.IO.DirectoryNotFoundException) &&
                                e.GetType() != typeof(System.IO.FileNotFoundException))
                            {
                                throw;
                            }
                        }
                    }
                }
                // pull the generated Assembly.Type from the assembly for configuration files
                if (progId.Length > 0 && strAssemblyName.Length > 0 && typeName.Length > 0)
                {
                    // write to the server configuration files
                    DiscoFile objDiscoFile = new DiscoFile();
                    string    strFileName  = PhysicalPath + "\\bin\\" + strAssemblyName + ".dll";
                    if (bDelete)
                    {
                        SoapServerConfig.DeleteComponent(PhysicalPath + "\\Web.Config", strAssemblyName, typeName, progId, strFileName);
                        objDiscoFile.DeleteElement(PhysicalPath + "\\Default.disco", progId + ".soap?WSDL");
                        // we have no way of telling from a single component what other components are in this type library
                        // metadata assembly.  If we remove from GAC or delete we kill all the other components simultaneously
                        //GacRemove(strFileName);
                        //File.Delete(strFileName);
                    }
                    else
                    {
                        SoapServerConfig.AddComponent(PhysicalPath + "\\Web.Config", strAssemblyName, typeName, progId, strFileName, "SingleCall", bWellKnown, bClientActivated);
                        if (bDiscoFile)
                        {
                            objDiscoFile.AddElement(PhysicalPath + "\\Default.disco", progId + ".soap?WSDL");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string Error = Resource.FormatString("Soap_PublishServerTlbFailure");
                ComSoapPublishError.Report(Error);
                if (typeof(ServicedComponentException) == e.GetType() || typeof(RegistrationException) == e.GetType())
                {
                    throw;
                }
            }
        }
Exemplo n.º 7
0
        /// <include file='doc\SoapServerTlb.uex' path='docs/doc[@for="SoapServerTlb.DeleteServerTlb"]/*' />
        public void DeleteServerTlb(
            string progId,
            string classId,
            string interfaceId,
            string srcTlbPath,
            string rootWebServer,
            string baseUrl,
            string virtualRoot,
            string operation,
            string assemblyName,
            string typeName
            )
        {
            try
            {
                SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
                sp.Demand();
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(System.Security.SecurityException))
                {
                    string Error = Resource.FormatString("Soap_SecurityFailure");
                    ComSoapPublishError.Report(Error);
                }
                throw;
            }
            Platform.Assert(Platform.Whistler, "SoapServerTlb.DeleteServerTlb");

            string strAssemblyName = assemblyName;

            if (progId.Length <= 0 && classId.Length <= 0 && assemblyName.Length <= 0 && typeName.Length <= 0)
            {
                return;
            }
            if (baseUrl.Length <= 0 && virtualRoot.Length <= 0)
            {
                return;
            }
            string PhysicalPath = SoapServerInfo.ServerPhysicalPath(rootWebServer, baseUrl, virtualRoot, false);
            string srcdll       = srcTlbPath.ToLower(CultureInfo.InvariantCulture);

            if (srcdll.EndsWith("scrobj.dll"))
            {
                return;                                  //not supported, nothing to do
            }
            if (srcdll.EndsWith("mscoree.dll"))
            {
                Type typ = Type.GetTypeFromProgID(progId);
                typeName = typ.FullName;
                Assembly     assem     = typ.Assembly;
                AssemblyName assemname = assem.GetName();
                strAssemblyName = assemname.Name;
            }
            else
            {
                GenerateMetadata metaGen = new GenerateMetadata();
                strAssemblyName = metaGen.GetAssemblyName(srcTlbPath, PhysicalPath + "\\bin\\");
                if (strAssemblyName.Length > 0)
                {
                    try
                    {
                        //TODO - review GetTypeNameFromProgId to determine if we can use the IID
                        // to simplify the logic
                        typeName = GetTypeName(PhysicalPath + "\\bin\\" + strAssemblyName + ".dll", progId, classId);
                    }
                    catch (Exception e)
                    {
                        if (e.GetType() != typeof(System.IO.DirectoryNotFoundException) &&
                            e.GetType() != typeof(System.IO.FileNotFoundException))
                        {
                            throw;
                        }
                    }
                }
            }
            // pull the generated Assembly.Type from the assembly for configuration files
            if (progId.Length > 0 && strAssemblyName.Length > 0 && typeName.Length > 0)
            {
                // write to the server configuration files
                DiscoFile discoFile   = new DiscoFile();
                string    strFileName = PhysicalPath + "\\bin\\" + strAssemblyName + ".dll";
                SoapServerConfig.DeleteComponent(PhysicalPath + "\\Web.Config", strAssemblyName, typeName, progId, strFileName);
                discoFile.DeleteElement(PhysicalPath + "\\Default.disco", progId + ".soap?WSDL");
                // we have no way of telling from a single component what other components are in this type library
                // metadata assembly.  If we remove from GAC or delete we kill all the other components simultaneously
                //GacRemove(strFileName);
                //File.Delete(strFileName);
            }
        }