Я пытаюсь использовать DLL в оболочке COM в классическом файле asp / vbscript, но не могу создать объект.
Файл DLLTest.asp выдает мне следующую ошибку:
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/DLLTest.asp, line 6
800401f3
Если я использую набор операторов if, я обнаружил, что проверяет существование объекта, я получаю следующее:
Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object: 'AddressVerification.AddressValidation'
/DLLTest.asp, line 7
Так что не удается создать объект.Когда я запускаю поиск в реестре, появляется доступный ключ, поэтому он, по-видимому, зарегистрирован.
Файл .bat записывается со следующим текстом:
"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;
}
}
}