2

I am attempting to use a COM-wrapped dll in a classic asp/vbscript file but am unable to create the object.

A DLLTest.asp file provides me with the following error:

Server object error 'ASP 0177 : 800401f3' 

Server.CreateObject Failed 

/DLLTest.asp, line 6 

800401f3 

If I use an if statement set I found that checks of the object's existence, I receive the following:

Microsoft VBScript runtime error '800a01ad' 

ActiveX component can't create object: 'AddressVerification.AddressValidation' 

/DLLTest.asp, line 7 

So it fails to create the object. When I run a search on the registry, there appears to be a key available so this does appear to be registered.

A .bat file is written with the following:

"C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" -i AddressVerification.dll

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe AddressVerification.dll

DLLTest.asp:

  <% 
    'Dim word, object

    'object=Server.CreateObject("AddressVerification.AddressValidation")
    'word=object.testMethod()

    if isObject(Createobject("AddressVerification.AddressValidation")) then 
        response.write "installed." 
    else 
        response.write "not installed." 
    end if 
    %>

    <HTML>
    </HTML>

AddressValidation.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Net;
    using System.Xml;
    using System.Runtime.InteropServices;
    using AddressVerification.Components;

    namespace AddressVerification
    {
    [ComVisible(true), GuidAttribute("41ef43e1-c1af-4a53-936b-8b6cc62ac534")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IAddressValidation
    {
    /*    string m_AccessLicenseNumber;
        string m_UserId;
        string m_Password; 

        string Password
        {
            get { return m_Password; }
            set { m_Password = value; }
        }

        string UserId
        {
            get { return m_UserId; }
            set { m_UserId = value; }
        }

        string AccessLicenseNumber
        {
            get { return m_AccessLicenseNumber; }
            set { m_AccessLicenseNumber = value; }
        } */

        string Password {get; set;}
        string UserId {get; set;}
        string AccessLicenseNumber {get; set;}


        string testMethod();
        string ValidateCityStateZip(string City, string StateProvinceCode, string             PostalCode);
        string ValidateStreetLevel(string ConsigneeName, string BuildingName, string  AddressLine1, string AddressLine2, string AddressLine3, string City, string StateProvinceCode, string PostcodePrimaryLow, string PostcodeExtendedLow, string CountryCode);
      }

      [ComVisible(true), GuidAttribute("41ef43e1-c1af-4a53-936b-8b6cc62ac534")]
      [ProgId("AddressVerification.AddressValidation")]
      [ClassInterface(ClassInterfaceType.AutoDual)]
      public class AddressValidation : IAddressValidation
    {

        #region Local Variables

            private string m_AccessLicenseNumber;
            private string m_UserId;
            private string m_Password;

        #endregion

        #region Constructor

            public AddressValidation()
            {
            }

            public AddressValidation(string accessLicenseNumber, string userId, string password)
            {
                m_AccessLicenseNumber = accessLicenseNumber;
                m_UserId = userId;
                m_Password = password;
            } 

        #endregion

        #region Properties

            public string Password
            {
                get { return m_Password; }
                set { m_Password = value; }
            }

            public string UserId
            {
                get { return m_UserId; }
                set { m_UserId = value; }
            }

            public string AccessLicenseNumber
            {
                get { return m_AccessLicenseNumber; }
                set { m_AccessLicenseNumber = value; }
            }

        #endregion

        public string testMethod()
        {
            string foo = "hooray!";
            return foo;
        }

        public string ValidateCityStateZip(string City, string StateProvinceCode, string PostalCode)
        {
            string result = "";
            string requestString = "";

            AccessRequest AccessReq = new AccessRequest(this.AccessLicenseNumber, this.UserId, this.Password);
            requestString += SerializeObj(AccessReq).InnerXml;

            // TODO: Use serialize object instead of fix xml code.
            requestString +=string.Format(@"<?xml version='1.0'?>
                                    <AddressValidationRequest xml:lang='en-US'>
                                       <Request>
                                          <TransactionReference>
                                             <CustomerContext>Customer Data</CustomerContext>
                                             <XpciVersion>1.0001</XpciVersion>
                                          </TransactionReference>
                                          <RequestAction>AV</RequestAction>
                                       </Request>
                                       <Address>
                                          <City>{0}</City>
                                          <StateProvinceCode>{1}</StateProvinceCode>
                                          <PostalCode>{2}</PostalCode>
                                       </Address>
                                    </AddressValidationRequest>", City, StateProvinceCode, PostalCode);

            // Return data in xml format
            result = UPSRequest("https://www.ups.com/ups.app/xml/AV", requestString);

            // TODO: Serialize return string to object
            return result;
        }

        public string ValidateStreetLevel(string ConsigneeName, string BuildingName, string AddressLine1, string AddressLine2, string AddressLine3, string City, string StateProvinceCode, string PostcodePrimaryLow, string PostcodeExtendedLow, string CountryCode)
        {
            string result = "";
            string requestString = "";

            AccessRequest AccessReq = new AccessRequest(this.AccessLicenseNumber, this.UserId, this.Password);
            requestString += SerializeObj(AccessReq).InnerXml;
            requestString += string.Format(@"<?xml version='1.0'?>
                                        <AddressValidationRequest xml:lang='en-US'>
                                            <Request>
                                                <TransactionReference>
                                                    <CustomerContext />
                                                    <XpciVersion>1.0001</XpciVersion>
                                                </TransactionReference>
                                                <RequestAction>XAV</RequestAction>
                                                <RequestOption>3</RequestOption>
                                            </Request>
                                            <MaximumListSize>3</MaximumListSize>
                                            <AddressKeyFormat>
                                                <ConsigneeName>{0}</ConsigneeName>
                                                <BuildingName>{1}</BuildingName>
                                                <AddressLine>{2}</AddressLine>
                                                <AddressLine>{3}</AddressLine>
                                                <AddressLine>{4}</AddressLine>
                                                <PoliticalDivision2>{5}</PoliticalDivision2>
                                                <PoliticalDivision1>{6}</PoliticalDivision1>
                                                <PostcodePrimaryLow>{7}</PostcodePrimaryLow>
                                                <PostcodeExtendedLow>{8}</PostcodeExtendedLow>
                                                <CountryCode>{9}</CountryCode>
                                            </AddressKeyFormat>
                                        </AddressValidationRequest>", 
                                        ConsigneeName, BuildingName,
                                        AddressLine1, AddressLine2, AddressLine3,
                                        City, StateProvinceCode, PostcodePrimaryLow, PostcodeExtendedLow, CountryCode);


            // Return data in xml format
            result = UPSRequest("https://onlinetools.ups.com/ups.app/xml/XAV", requestString);

            // TODO: Serialize return string to object
            return result;
        }

        private string UPSRequest(string url, string requestText)
        {
            string result = "";

            ASCIIEncoding encodedData = new ASCIIEncoding();
            byte[] byteArray = encodedData.GetBytes(requestText);

            // open up da site
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
            wr.Method = "POST";
            wr.KeepAlive = false;
            wr.UserAgent = "Benz";
            wr.ContentType = "application/x-www-form-urlencoded";
            wr.ContentLength = byteArray.Length;
            try
            {
                // send xml data
                Stream SendStream = wr.GetRequestStream();
                SendStream.Write(byteArray, 0, byteArray.Length);
                SendStream.Close();

                // get da response
                HttpWebResponse WebResp = (HttpWebResponse)wr.GetResponse();
                using (StreamReader sr = new StreamReader(WebResp.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }


                WebResp.Close();
            }
            catch (Exception ex)
            {
                // Unhandle exception occure
                result = ex.Message;
            }

            return result;
        }

        // Serialize Object to XML
        private System.Xml.XmlDocument SerializeObj(Object obj)
        {
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

            try
            {
                using (System.IO.MemoryStream myStream = new System.IO.MemoryStream())
                {
                    System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
                    xmlSer.Serialize(myStream, obj);
                    myStream.Position = 0;
                    xmlDoc.Load(myStream);
                }
            }
            catch (Exception ex)
            {
            }
            return xmlDoc;
        }
    }
}
dbc
  • 104,963
  • 20
  • 228
  • 340
Seraph812
  • 397
  • 3
  • 7
  • 17

2 Answers2

1

Here is a list of things you may want to check

A: This error means "Invalid class string" -- in other words the call to CreateObject failed because the name object cannot be found by the OLE sub-system. Causes include:

  1. You really didn't run regsvr32 on the server after all.
  2. You ran regsvr32 but it reported an error.
  3. Someone modified security on part of the registry that's preventing the OLE subsystem from reading all or part of the HKEY_CLASSES_ROOT tree.
  4. The name of the object you are trying to create was mispelled or is incorrect.
  5. Determine if it's a permissions problem

Add the anonymous user (used by IIS) to the Administrators group. The test page then worked, proving it was a permissions problem. Do not forget to remove the anonymous IIS user from the Admin group!

  1. Determine if it is a file permissions problem:

After removing the Anonymous user from the Admin group, add failure auditing to the file (smtpsvg.dll), which will determine if the file was ever accessed (by the lack of the failure event). If it isn't, this makes it clear that the failure is prior to file access but go ahead and check file/directory permissions to make sure the anonymous IIS user can access the file.

  1. Check registry permissions

Using Regedt32, do find on smtpsvg.dll. Check the permissions for the key (and sub keys), and make sure that the anonymous user has read rights. Do a find on the class-id, which contains the location value, and version, and check those permissions as well.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
MethodMan
  • 18,625
  • 6
  • 34
  • 52
0

Have you tested the .NET component as a COM component from VBScript or some other language the consumes COM?

It doesn't appear to me that your set of attributes on in the .NET code is correct. You have given both the IAddressValidation and AddressValidation the same Guid, so thats a bit odd. You really want your .NET code to look like this.

[ComVisible(true), Guid("41ef43e1-c1af-4a53-936b-8b6cc62ac534")] 
[InterfaceType(ComInterfaceType.InterfaceIsDual)] 
public interface IAddressValidation 


[ComVisible(true), Guid("ebef29ba-fa88-4644-b249-5b40f1ba19da")]  
[ProgId("AddressVerification.AddressValidation")]  
[ClassInterface(ClassInterfaceType.None)]  
public class AddressValidation : IAddressValidation  

You just want the AddressValidation to expose the default interface to IAddressValidation so the class itself should have ClassInterfaceType.None.

The other thing you should do is include /Codebase when performing regasm, otherwise COM has no idea where to find the actual physical .dll file. Regasm will complain but it will do it.

Actually scratch that I've just seen your are installing into the GAC. However it might be worth trying it without using the GAC and using /codebase instead if you are still not getting anywhere.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306