Re: Cannot instantiate .NET Class Library to expose webservice client library
From: Patrick (patl_at_reply.newsgroup.msn.com)
Date: 09/29/04
- Next message: Martin Dobson: "VB.Net Web Service using sockets"
- Previous message: Alfred B. Thordarson: "Re: <wsdlHelpGenerator> causing problems with web-service references !?!"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 29 Sep 2004 15:30:32 +0100
Now that I have got the mickey mouse .NET interop problem sorted (exposing
.NET library to ASP/VB6), I want to demo the real problem I am having.
What I want to achive is actually expoing a C#.NET Class Library for making
Web Service calls to ASP pages.
>From my mickey mouse example, I learnt the following:
1) It's best to define interfaces as follows:
--------------------start of interface--------------------
using System.Runtime.InteropServices;
namespace MyOrg.web.publications
{
//[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://twoten.press.
net/webservices/")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
public interface ITest
{
void DoSomething();
}
}
--------------------end of interface--------------------
2) The class, I just need to implement the interface (other than using
[ClassInterface(ClassInterfaceType.AutoDual)])
3) install the .NET dll into gac
4) use regasm to install the type library
5) the DLL usable with Late Binding:
e.g. Set objTest = CreateObject("MyOrg.web.publications.Test")
***The real real use/problem I am having is as follows:
(The code for the web service client class library is as follows)
---------------Start of WebService client Class Library Code---------------
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.IO;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
using System.Runtime.InteropServices;
namespace MyOrg.web.publications
{
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="iOrderSoap",
Namespace="http://testServer/webservices/")]
public class Order : Microsoft.Web.Services2.WebServicesClientProtocol ,
IOrder
{
/// <remarks/>
public Order()
{
this.Url = "https://testServer/iPubData/iOrder.asmx";
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://Pub.press
.net/webservices/PlaceOrder",
RequestNamespace="http://Pub.press.net/webservices/",
ResponseNamespace="http://Pub.press.net/webservices/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void PlaceOrder(SimpleOrderData order)
{
try
{
StreamWriter fileStream;
fileStream = File.CreateText("c:\\temp\\test.txt");
fileStream.WriteLine("TestOrder=" + order.TestOrder);
fileStream.WriteLine("FirstName" + order.FirstName);
fileStream.WriteLine("Surname" + order.Surname );
fileStream.WriteLine("order.OrderLines(0).StockCode" +
order.OrderLines[0].StockCode);
fileStream.Flush();
fileStream.Close();
//fileStream.WriteLine("" + );
// this.Invoke("PlaceOrder", new object[] {
// order});
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex);
}
}
/// <remarks/>
public System.IAsyncResult BeginPlaceOrder(SimpleOrderData order,
System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("PlaceOrder", new object[] {
order}, callback, asyncState);
}
/// <remarks/>
public void EndPlaceOrder(System.IAsyncResult asyncResult)
{
this.EndInvoke(asyncResult);
}
}
---------------End of WebService client Class Library Code---------------
1) I could compile, gacutil /i and regasm the class library with no problem
2) When I try to use it in ASP as follows:
2.1) Set objOnlyOrder =
CreateObject("MyOrg.web.publications.SimpleOrderData")
2.2) I get the following error:
------------------------start of asp error------------------------
Active Server Pages error 'ASP 0115'
Unexpected error
/test.asp
A trappable error (C0000005) occurred in an external object. The script
cannot continue running.
------------------------end of asp error------------------------
3.1) If I try to use it from VBA with Early Binding, then there are no
errors, but the class library doesn't seem to be reading reading in the
write value by writing to "C:\temp\test.txt" (it simply creates a blank
test.txt file)!
-------------------------start of VBA Code-------------------------
Dim objOnlyOrderLine As New iPubClient.OrderLine
Dim objOnlyOrder As New iPubClient.SimpleOrderData
Dim objIPubClient As New iPubClient.Order
Dim arrOrderLines(0) As String
objOnlyOrderLine.StockCode = "A123"
objOnlyOrderLine.Quantity = 2
objOnlyOrder.TestOrder = True
objOnlyOrder.FirstName = "Mickey"
objOnlyOrder.Surname = "Mouse"
arrOrderLines(0) = objOnlyOrderLine
objOnlyOrder.OrderLines = arOrderLines
MsgBox "before"
objIPubClient.PlaceOrder objOnlyOrder
MsgBox "after"
Set objOnlyOrderLine = Nothing
Set objOnlyOrder = Nothing
Set objIPubClient = Nothing
-------------------------End of VBA Code-------------------------
"Richard Blewett [DevelopMentor]" <richardb@develop.com> wrote in message
news:eWZObygpEHA.3300@TK2MSFTNGP12.phx.gbl...
> Have a look in the registry and find out what the InprocServer32 key looks
like for your .NET object.
>
> Also, ASP and vbscript are creating the object via its progid - is
testInterop.test the fully qualified name (including full namespace) of the
class you are trying to create?
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://staff.develop.com/richardb/weblog
>
>
nntp://news.microsoft.com/microsoft.public.dotnet.framework/
>
> This is weird.....
>
> I tried exactly what you did:
> 1) I could do the following in Microsoft Word 2003 Macro (after adding a
> reference to testInterop.tlb):
> ------------------------start of functioning VBA
> Code------------------------
> Dim objTest As New testInterop.test
> objTest.DoSomething
> ------------------------end of functioning VBA
Code------------------------
> 2.1) When I try the following ASP code on Windows XP Professional SP1
with
> IIS5.1
> -----------------------------startof ASP
Code-----------------------------
> <%
> Dim objTest
> Set objTest = CreateObject("testInterop.test")
> objTest.DoSomething
> %>
> ------------------------------end of ASP
Code------------------------------
> 2.2) I still get the following error
> --------------------------------start of ASP
> error--------------------------------
> Microsoft VBScript runtime error '800a01ad'
>
> ActiveX component can't create object: 'testInterop.test'
>
> /testInterop.asp, line 3
> --------------------------------end of ASP
> error--------------------------------
> 3) If I put the ASP code in VBScript, I get the following error:
> ----------------------------start of VBScript
> Error---------------------------
> C:\Temp\testactivex.vbs(2, 5) Microsoft VBScript runtime error: ActiveX
> componen
> t can't create object: 'testInterop.test'
> ----------------------------end of VBScript
Error---------------------------
>
> Why is this and how could this be resolved?
>
> "Richard Blewett [DevelopMentor]" <richardb@develop.com> wrote in message
> news:uIHwqBZpEHA.2304@TK2MSFTNGP14.phx.gbl...
> > I assume you have not given the assembly a strong name and installed it
in
> the GAC. The problem is that the COM loader gets pointed to mscoree.dll
(the
> runtime) and then passes mscoree.dll the CLSID of the COM object (via
> DllGetClassObject) mscoree goes to the registry and looks under that
CLSID
> and finds the assembly name, class anme and a bunch of other stuff. Now
the
> problem is mscoree doesn't know where your class is so it tries to load
it
> by name and fails dismally as the assembly isn't in the APPBASE (or
> subdirectory) of the executing process (cscript.exe or inetinfo.exe I
guess
> in these scenarios).
> >
> > Just to show things working, change your regasm command line to
> >
> > regasm /tlb:testInterop.tlb testInterop.dll /codebase
> >
> > You will get a warning about the assembly not having a strong name but
> just ignore that for now. Hopefully enverything will now work (regasm
puts
> the path to the assembly - the CODEBASE - under the CLSID as well so
mscoree
> knows where to find it).
> >
> > In reality however, you should strong name and GAC the interop assembly
> >
> > Regards
> >
> > Richard Blewett - DevelopMentor
> > http://staff.develop.com/richardb/weblog
> >
> >
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004
>
>
>
> [microsoft.public.dotnet.framework]
Relevant Pages
... Web Service calls to ASP pages. ... gacutil /i and regasm the class library with no problem ... Dim objOnlyOrderLine As New iPubClient.OrderLine ... Dim objOnlyOrder As New iPubClient.SimpleOrderData ...
(microsoft.public.dotnet.framework)
... I originally started with an ASP page that returned the XML data island. ... > Dim objDoc As Object ... > Dim strHTML As String ...
(microsoft.public.scripting.vbscript)
... I am currently trying to get a simple data submission asp form to export ... dim Name ... Database was successfully updated. ... Dim sMSG ...
(microsoft.public.inetserver.asp.db)
... Your code runs fine in ASP on my box. ... > Dim sConn As String ... the web site or my firewall software (McAfee ...
(microsoft.public.inetserver.iis)
... ASP application over the web. ... "Basic Authentication" enabled. ... Dim oRootDSE As IADs ... strPassword As String, strUserADSPath As String ...
(microsoft.public.inetserver.iis.security)