开发者

Calling of .NET Function Taking inputs as objects from Classic ASP

This is strange for me. I was able to set up the environment so that I can call .NET method (via COM) from a classic ASP page.

Everything actually works as intended until when I have to call a .NET method that requires a .NET type.

So I have a method named

I have a function like this in .Net

Public Sub SetTable(ByVal _City As City, ByVal _Country As Country)
          'doing some thing
End Sub

and i have asp code like this:

dim CountryUtil, City, Country
set CountryUtil= Server.CreateObject("mydll.CountryUtil")
set city = Server.CreateObject("mydll.City")
set Country = Server.CreateObject("mydll.Country")
city.id= 123
city.property = "so开发者_开发百科 and so"

Country.id= 123
Country.property = "so and so"

categoryUtil.SetTable(City, Country)

' I get this error here:

'Microsoft VBScript runtime error '800a0005' 'Invalid procedure call or argument: 'SetTable'

Thanks in advance.


if countryUtil is a class, you might have to initiate a new instance of it first.
Also, instead of Setting, you can just create new variables. Don't forget case sensitivity. If you try to pass the City instead of the city, it will give you problems.

''# Create a new instance of the categoryUtil Class
Dim countryUtil As New mydll.CountryUtil 

Dim city As New mydll.City
Dim country As New mydll.Country

city.id= 123
city.property = "so and so"

country.id= 123
country.property = "so and so"

''# Instead of using the Class directly, you use the new instance of the Class
''# and pass the lowercase variables instead of the UpperCase Classes.
countryUtil.SetTable(city, country)

EDIT

If you were using a later version of the .NET framework, you could shorten it like this

''# Create a new instance of the categoryUtil Class
Dim countryUtil As New mydll.CountryUtil 

Dim city As New mydll.City With {.id = 123, .property="so and so"}
Dim country As New mydll.Country With {.id=123, .property="so and so"}


''# Instead of using the Class directly, you use the new instance of the Class
''# and pass the lowercase variables instead of the UpperCase Classes.
countryUtil.SetTable(city, country)

EDIT

Check out this link to see how to mix asp and asp.net
http://knol.google.com/k/from-classic-asp-to-asp-net-and-back#


ASP values you set as values for the params are VARIANT. But you defined different variable types in your function.

Example:

.NET Code:

Public Sub Test(param as String)

Classic ASP:

Dim yourParam : yourParam = "Testvalue"
YourClass.Test(yourParam)

This will fail.

Classic ASP:

Dim yourParam : yourParam = "Testvalue"
YourClass.Test(CStr(yourParam))

This will work.

So as resolution you need to take care to set the correct variable types while you call your function! In classic ASP everything is VARIANT. Sidenote: Dictionary Objects, Array's are tricky to handle, I managed to define in .NET my variables as object[] and convert them inside the class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜