Professional Web Applications Themes

Cannot instantiate .NET Class Library to expose webservice client library - ASP.NET Web Services

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(Namespac e="http://twoten.press. net/webservices/")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)] public interface ITest { void DoSomething(); } } --------------------end of interface-------------------- 2) The class, I just need to implement the interface (other than ...

  1. #1

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    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(Namespac e="http://twoten.press.
    net/webservices/")]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)]
    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("c ode")]
    [System.Web.Services.WebServiceBindingAttribute(Nam e="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.SoapDoentMethodAt tribute("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.SoapP arameterStyle.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).StockCod e" +
    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.SimpleOrderDa ta")
    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]" <richardbdevelop.com> wrote in message
    news:eWZObygpEHA.3300TK2MSFTNGP12.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
    > [url]http://staff.develop.com/richardb/weblog[/url]
    >
    >
    nntp://news.microsoft.com/microsoft.public.dotnet.framework/<On0O3lgpEHA.868TK2MSFTNGP10.phx.gbl>
    >
    > 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]" <richardbdevelop.com> wrote in message
    > news:uIHwqBZpEHA.2304TK2MSFTNGP14.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
    > > [url]http://staff.develop.com/richardb/weblog[/url]
    > >
    > >
    >
    >
    >
    > ---
    > Incoming mail is certified Virus Free.
    > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004
    >
    >
    >
    > [microsoft.public.dotnet.framework]

    Patrick Guest

  2. #2

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    Hi Patrick,

    It may be a Permission and authentication issue with files and registry
    keys. Errors may occur if the authenticated user does not have sufficient
    permissions on other files such as custom components, system dynamic- link
    libraries (DLLs), and even registry keys. ASP scripts are typically
    executed in the security context of the IUSR_<machine_name> account. If you
    believe you are dealing with a permissions problem in the registry, you can
    use Regedt32.exe to examine ermissions on the various registry keys.

    The first step is to determine if you really are seeing a permissions
    problem. A good test is to temporarily add the anonymous logon account
    (IUSR_<machine_name>) to the administrators group using User Manager. This
    gives the IUSR_<machine_name> account administrative privileges on the
    computer. If this causes ASP to function properly, you are almost
    certainly dealing with a permissions issue.

    Luke

    [MSFT] Guest

  3. #3

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    I could confirm that this is 101% not a permission issue. The following
    might be interesting summary of my observation
    1) Added IUSR_<machineName> to local administrators group does NOT solve the
    problem.
    2) Just to clarify in the ASP Code, the following code does work with no
    problem
    Set objOnlyOrderLine =
    CreateObject("MyOrg.web.publications.OrderLine")
    Set objOnlyOrder =
    CreateObject("MyOrg.web.publications.SimpleOrderDa ta")
    3) The following line fails:
    Set objITwoTenDataClient =
    CreateObject("MyOrg.web.publications.Order")

    4) I haven't include the code for OrderLine or SimpleOrderData, but
    effectively they are "Data classes" which takes contains public members no
    funkier than String, Integer and String[] (types all tested under my micket
    mouse example posted at
    nntp://news.microsoft.com/microsoft.public.dotnet.framework under the
    subject "Re: Cannot instantiate .NET Class Library")

    5) NOTE- My Order class *inherits* .NET Managed class
    Microsoft.Web.Services2.WebServicesClientProtocol. This is a key difference
    between my Data Class (which instantiates ok) and my mickey mouse Test class

    6) I could instantiate the Order class and call it from VBA, but it doesn't
    produce the desired outcome (it merely creates the blank file
    c:\temp\test.txt)

    7) Cannot use Late Binding to create Order class from VBA or ASP!

    "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    news:EBUHDlrpEHA.3312cpmsftngxa06.phx.gbl...
    > Hi Patrick,
    >
    > It may be a Permission and authentication issue with files and registry
    > keys. Errors may occur if the authenticated user does not have
    sufficient
    > permissions on other files such as custom components, system dynamic-
    link
    > libraries (DLLs), and even registry keys. ASP scripts are typically
    > executed in the security context of the IUSR_<machine_name> account. If
    you
    > believe you are dealing with a permissions problem in the registry, you
    can
    > use Regedt32.exe to examine ermissions on the various registry keys.
    >
    > The first step is to determine if you really are seeing a permissions
    > problem. A good test is to temporarily add the anonymous logon account
    > (IUSR_<machine_name>) to the administrators group using User Manager.
    This
    > gives the IUSR_<machine_name> account administrative privileges on the
    > computer. If this causes ASP to function properly, you are almost
    > certainly dealing with a permissions issue.
    >
    > Luke
    >

    Patrick Guest

  4. #4

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    Hi Patrick,

    Can the "MyOrg.web.publications.Order" be create in a .NET app? And create
    the file?

    Luke

    [MSFT] Guest

  5. #5

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    Yes

    "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    news:2R8BCQtpEHA.3212cpmsftngxa06.phx.gbl...
    > Hi Patrick,
    >
    > Can the "MyOrg.web.publications.Order" be create in a .NET app? And create
    > the file?
    >
    > Luke
    >

    Patrick Guest

  6. #6

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    I still couldn't get this working :-(

    I *suspect* it is something to do with the fact my client class inherits
    from Microsoft.Web.Services2.WebServicesClientProtocol, which obviously is a
    ..NET Managed class. I can't think of how I could expose that as well as the
    inheritance tree to COM (in fact, I think inheritance tree are flattened).
    In fact, I very much suspect, the class is having trouble looking for
    this.url (which is from the base class). Is there a solution to this
    (without having to re-write WebServicesClientProtocol)?

    "Patrick" <patlreply.newsgroup.msn.com> wrote in message
    news:uAgdgDjpEHA.324TK2MSFTNGP11.phx.gbl...
    > 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(Namespac e="http://twoten.press.
    > net/webservices/")]
    > [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)]
    > 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("c ode")]
    > [System.Web.Services.WebServiceBindingAttribute(Nam e="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.SoapDoentMethodAt tribute("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.SoapP arameterStyle.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).StockCod e" +
    > 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.SimpleOrderDa ta")
    > 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]" <richardbdevelop.com> wrote in message
    > news:eWZObygpEHA.3300TK2MSFTNGP12.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
    > > [url]http://staff.develop.com/richardb/weblog[/url]
    > >
    > >
    >
    nntp://news.microsoft.com/microsoft.public.dotnet.framework/<On0O3lgpEHA.868TK2MSFTNGP10.phx.gbl>
    > >
    > > 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]" <richardbdevelop.com> wrote in
    message
    > > news:uIHwqBZpEHA.2304TK2MSFTNGP14.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
    > > > [url]http://staff.develop.com/richardb/weblog[/url]
    > > >
    > > >
    > >
    > >
    > >
    > > ---
    > > Incoming mail is certified Virus Free.
    > > Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    > > Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004
    > >
    > >
    > >
    > > [microsoft.public.dotnet.framework]
    >
    >

    Patrick Guest

  7. #7

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    Hi Patrick,

    I just create a simple sample:


    [System.Web.Services.WebServiceBindingAttribute(Nam e="iOrderSoap",
    Namespace="http://localhost/webservice1/")]
    public class Class1:Microsoft.Web.Services2.WebServicesClientPr otocol
    {
    public Class1()
    {
    this.Url ="http://localhost/webservice1/service1.asxm";


    }
    }

    And tested it within an ASP project, It seems the object was created
    successfully.

    Is it possible that the problem is related to the interface "IOrder", if
    you temprorily remove this interface, what will be the result?
    Additionally, when you perform the test, I suggest you may disable the
    anonymous access and use windows intergrated authentication. And reset IIS.

    Luke

    [MSFT] Guest

  8. #8

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    I have modified my class slightly (getting it to write to Event Viewer
    instead of a text file), code appended at the end of this post:
    1) When invoked from a .NET client, the class library performed as expected,
    logging the passed in object (and it's public members) to the application
    log of the Event Viewer
    2) I performed the following step to get interop working:
    2.1) gacutil -i iMyClient.dll
    2.2) regasm /tlb:MyClient.tlb MyClient.dll (also tried adding a /codebase
    option, but makes no difference)
    3) I created a VB6 (not .NET) project as follows:
    3.1) Added project reference to MyClient.tlb
    3.2) Created a form, with a button's code behind code as follows:
    '-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!Start of VB6 Client
    Code-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!Private Sub Command1_Click()
    Dim objIMyClient As New Order
    Dim objOnlyOrderLine As New OrderLine
    Dim objOnlyOrder As New SimpleOrderData
    Dim arrOrderLines(1)
    On Error GoTo errorHandler

    objOnlyOrderLine.StockCode = "A123"
    objOnlyOrderLine.Quantity = 2

    objOnlyOrder.TestOrder = True
    objOnlyOrder.FirstName = "Mickey"
    objOnlyOrder.Surname = "Mouse"

    arrOrderLines(0) = objOnlyOrderLine
    objOnlyOrder.OrderLines = arOrderLines

    MsgBox "before"
    objIMyClient.PlaceOrder objOnlyOrder
    MsgBox "after"

    errorHandler:
    Set objOnlyOrderLine = Nothing
    Set objOnlyOrder = Nothing

    Set objIMyClient = Nothing
    MsgBox Err.Description
    End Sub
    '-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!End of VB6 Client
    Code-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
    3.3) The VB client runs OK, Message-boxing, "before", "after" and blank
    (denoting no errors
    3.4) Nothing is logged in event viewer (NOTE, when the web service is
    writing to text file, it merely creates a blank c:\temp\test.txt)
    3.5) I believe there should be NO permission issues here, because the VB6
    code is run in the same context as the .NET test client (which logs to Event
    Viewer OK). I am logged on as a local administrator on Windows XP
    Professional SP1
    3.6) Now, I can't even tell what is wrong!
    3.6.1) Can't write to event viewer, text file OR
    3.6.2) Can't read the incoming objects?

    4.1) Now, if I run it in VBScript as follows:
    '-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!Start of VBScript
    Code-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
    Dim objITwoTenDataClient,objOnlyOrderLine,objOnlyOrder
    Dim arrOrderLines(1)
    Set objOnlyOrderLine = CreateObject("YJB.web.publications.OrderLine")
    Set objOnlyOrder =
    CreateObject("YJB.web.publications.SimpleOrderData ")
    Set objITwoTenDataClient = CreateObject("YJB.web.publications.Order")

    objOnlyOrderLine.StockCode = "A123"
    objOnlyOrderLine.Quantity = 2

    objOnlyOrder.TestOrder = true
    objOnlyOrder.FirstName = "Mickey"
    objOnlyOrder.Surname = "Mouse"

    arrOrderLines(0) = objOnlyOrderLine
    objOnlyOrder.OrderLines = arOrderLines
    MsgBox "7"

    objITwoTenDataClient.PlaceOrder objOnlyOrder
    MsgBox "8"
    Set objOnlyOrderLine = Nothing
    Set objOnlyOrder = Nothing

    Set objITwoTenDataClient = Nothing

    MsgBox "9"
    '-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!End of VBScript
    Code-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
    4.2) I get the following Message Boxed:
    4.2.1) 7
    4.2.2) Windows Scripting Host
    Script: C:\temp\testActiveX.vbs
    Line: 18
    Char: 1
    Error: Invalid procedure call or argument: 'PlaceOrder'
    Code: 800A0005
    Source: Microsoft VBScript runtime error

    5) More interesting, on to ASP problem (this is how I intend to use it) with
    Late Binding:
    5.1) Turn off Anonymous access, enable integrated windows authentication
    5.2) Try to load an ASP containing
    '-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!Start of ASP Client
    Code-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-
    <% Language = "VBScript" %>
    <%
    Dim objMyClient,objOnlyOrderLine,objOnlyOrder
    Dim arrOrderLines(1)
    %>
    1
    <%
    Set objOnlyOrderLine = CreateObject("MyOrg.web.publications.OrderLine")
    %>
    2
    <%

    Set objOnlyOrder =
    CreateObject("MyOrg.web.publications.SimpleOrderDa ta")
    %>
    3
    <%

    Set objMyClient = CreateObject("MyOrg.web.publications.Order")
    %>
    4
    <%


    Set objOnlyOrderLine.StockCode = "A123"
    Set objOnlyOrderLine.Quantity = 2
    %>
    5
    <%

    Set objOnlyOrder.TestOrder = true
    Set objOnlyOrder.FirstName = "Mickey"
    Set objOnlyOrder.Surname = "Mouse"
    %>
    6
    <%

    arrOrderLines(0) = objOnlyOrderLine
    Set objOnlyOrder.OrderLines = arOrderLines
    %>
    7
    <%

    objMyClient.PlaceOrder objOnlyOrder
    %>
    8
    '-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!End of ASP Client
    Code-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
    5.2) I get the following displayed on ASP Page:
    ********************start of ASP Output********************
    1 2 3
    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 Output********************


    /******************start of web service client******************/
    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 YJB.web.publications
    {
    /// <remarks/>
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("c ode")]
    [System.Web.Services.WebServiceBindingAttribute(Nam e="iOrderSoap",
    Namespace="http://twoten.press.net/webservices/")]
    public class Order : Microsoft.Web.Services2.WebServicesClientProtocol ,
    IOrder
    {

    /// <remarks/>
    public Order()
    {
    this.Url = "https://www.mytwotendata.press.net/iTwoTenData/iOrder.asmx";
    }

    /// <remarks/>

    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://twoten.pr
    ess.net/webservices/GetVersion",
    RequestNamespace="http://twoten.press.net/webservices/",
    ResponseNamespace="http://twoten.press.net/webservices/",
    Use=System.Web.Services.Description.SoapBindingUse .Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    public string GetVersion()
    {
    object[] results = this.Invoke("GetVersion", new object[0]);
    return ((string)(results[0]));
    }

    /// <remarks/>
    public System.IAsyncResult BeginGetVersion(System.AsyncCallback callback,
    object asyncState)
    {
    return this.BeginInvoke("GetVersion", new object[0], callback,
    asyncState);
    }

    /// <remarks/>
    public string EndGetVersion(System.IAsyncResult asyncResult)
    {
    object[] results = this.EndInvoke(asyncResult);
    return ((string)(results[0]));
    }

    /// <remarks/>

    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://twoten.pr
    ess.net/webservices/PlaceOrder",
    RequestNamespace="http://twoten.press.net/webservices/",
    ResponseNamespace="http://twoten.press.net/webservices/",
    Use=System.Web.Services.Description.SoapBindingUse .Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.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).StockCod e" +
    order.OrderLines[0].StockCode);
    //fileStream.Flush();
    //fileStream.Close();
    ////fileStream.WriteLine("" + );
    //// this.Invoke("PlaceOrder", new object[] {
    //// order});
    String Temp = "";
    EventLog objEventLog = new EventLog();


    Temp += "test of ";
    Temp += System.DateTime.Now.ToString() + "\n";
    Temp += "TestOrder=" + order.TestOrder + "\n";
    Temp += "FirstName" + order.FirstName + "\n";
    Temp += "Surname" + order.Surname + "\n";
    Temp += "order.OrderLines(0).StockCode" + order.OrderLines[0].StockCode
    ;

    objEventLog.Log = "Application";
    objEventLog.Source = ".NET Runtime";

    objEventLog.WriteEntry(Temp,EventLogEntryType.Info rmation);

    }
    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);
    }

    /// <remarks/>

    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://twoten.pr
    ess.net/webservices/PlaceOrders",
    RequestNamespace="http://twoten.press.net/webservices/",
    ResponseNamespace="http://twoten.press.net/webservices/",
    Use=System.Web.Services.Description.SoapBindingUse .Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    public void PlaceOrders(SimpleOrderData[] order)
    {
    this.Invoke("PlaceOrders", new object[] {
    order});
    }

    /// <remarks/>
    public System.IAsyncResult BeginPlaceOrders(SimpleOrderData[] order,
    System.AsyncCallback callback, object asyncState)
    {
    return this.BeginInvoke("PlaceOrders", new object[] {
    order}, callback, asyncState);
    }

    /// <remarks/>
    public void EndPlaceOrders(System.IAsyncResult asyncResult)
    {
    this.EndInvoke(asyncResult);
    }
    }

    }
    /******************end of web service client******************/


    Patrick Guest

  9. #9

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    Right!

    I *think* I have got down to *part of* what is causing this problem:
    If I update the WebService class' PlaceOrder and related method to take a
    String parameter as opposed to a SimpleOrderData object, then:
    1) VBScript runs OK, with input parameter written to text file
    2) ASP invocation (using same code and Late Binding) still produces "A
    trappable error (C0000005) occurred in an external object. The script cannot
    continue running. "
    3) ISimpleOrderData.cs, SimpleOrderData.cs, IOrderLine.cs and OrderLine.cs
    are all included in the same Class library .NET project and compiled
    together (the code are appended below for reference). Note, I have included
    interfaces here because I have read from the Microsoft site that it's better
    to definte ur own interface then to rely on regasm to auto generate class
    interfaces.

    /********************start of ISimpleOrderData.cs********************/
    using System;
    using System.Runtime.InteropServices;


    namespace MyOrg.web.publications
    {
    /// <summary>
    /// Summary description for OrderLine.
    /// </summary>


    [System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://testserver/webs
    ervices/")]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)]
    public interface ISimpleOrderData
    {
    }
    }
    /********************end of ISimpleOrderData.cs********************/

    /********************start of SimpleOrderData.cs********************/
    using System;
    using System.Runtime.InteropServices;

    namespace MyOrg.web.publications
    {
    /// <summary>
    /// Represent iTwoTenData's SimpleOrderData data class
    /// </summary>

    [System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://testserver/webs
    ervices/")]
    public class SimpleOrderData : ISimpleOrderData
    {
    public SimpleOrderData()
    {
    //
    // TODO: Add constructor logic here
    //
    }


    /// <remarks/>
    public System.Guid CorrelationID;

    /// <remarks/>
    public string Endpoint;

    /// <remarks/>
    public bool TestOrder;

    /// <remarks/>
    public string Title;

    /// <remarks/>
    public string FirstName;

    /// <remarks/>
    public string Surname;

    /// <remarks/>
    public string AccountName;

    /// <remarks/>
    public string Address1;

    /// <remarks/>
    public string Address2;

    /// <remarks/>
    public string Address3;

    /// <remarks/>
    public string Address4;

    /// <remarks/>
    public string Address5;

    /// <remarks/>
    public string PostCode;

    /// <remarks/>
    public string CustomerCountryCode;
    }
    /********************end of SimpleOrderData.cs********************/

    /********************start of IOrderLine.cs********************/
    using System;
    using System.Runtime.InteropServices;


    namespace MyOrg.web.publications
    {
    /// <summary>
    /// Summary description for OrderLine.
    /// </summary>


    [System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://testserver/webs
    ervices/")]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)]
    public interface IOrderLine
    {
    }
    }
    /********************end of IOrderLine.cs********************/


    /********************start of OrderLine.cs********************/
    using System;


    namespace MyOrg.web.publications
    {
    /// <summary>
    /// Summary description for OrderLine.
    /// </summary>


    [System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://testserver/webs
    ervices/")]
    public class OrderLine : IOrderLine
    {
    public OrderLine()
    {
    //
    // TODO: Add constructor logic here
    //
    }

    /// <remarks/>
    public string OrderLineNo;

    /// <remarks/>
    public string StockCode;

    /// <remarks/>
    public int Quantity;

    /// <remarks/>
    public string UnitValue;

    }
    }

    /********************end of OrderLine.cs********************/


    Patrick Guest

  10. #10

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    I can confirm regrettably, that I can't even instantiate the .NET class
    SimpleWSTest appended at the end of this post from ASP (I could do so from
    VBScript):

    1) If I run it in ASP (having turned on ONLY integrated windows
    authentication and logging in as someon with admin rights on the IIS 5.1
    machine(winXP Pro SP1), I get the following returned using
    1.1)
    '-!-!-!-!-!-!-!-!-!-!-Start of ASP Code-!-!-!-!-!-!-!-!-!-!-
    <% Language = "VBScript" %>
    <%
    Dim objITwoTenDataClient
    %>
    1
    <%
    'MyOrg.web.publications.
    Set objITwoTenDataClient = CreateObject("SimpleWSTest")
    %>
    2
    '-!-!-!-!-!-!-!-!-!-!-End of ASP Code-!-!-!-!-!-!-!-!-!-!-

    1.2) I get the following returned
    ----------Start of ASP Output----------
    1 error '80131522'
    /test3.asp, line 8

    ----------End of ASP Output----------

    2) If I run the equivalent from VBScript, I get no error returned (object
    could be created and destroyed with Late Binding, but of course I can't tell
    if it's "working" or not).



    /********************Start of SimpleWSTest class********************/
    using System;
    using System.Web.Services;
    using System.Runtime.InteropServices;
    using System.IO;

    //namespace MyOrg.web.publications
    //{

    [System.Web.Services.WebServiceBindingAttribute(Nam e="iOrderSoap",
    Namespace="http://localhost/webservice1/")]
    [System.ComponentModel.DesignerCategoryAttribute("c ode")]
    public class SimpleWSTest :
    Microsoft.Web.Services2.WebServicesClientProtocol
    {

    public SimpleWSTest()
    {
    this.Url = "https://testserver/Order/iOrder.asmx";
    }
    }
    //}
    /********************End of SimpleWSTest class********************/


    Patrick Guest

  11. #11

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    I can also confirm that I persistently get a "error '80131522' " from ASP
    regardless of the following:

    1) use regasm with a /CODEBASE switch. i.e. regasm /tlb:SimpleWSTest.tlb
    SimpleWSTest.dll /codebase
    2) use regasm without a /CODEBASE switch. i.e. regasm /tlb:SimpleWSTest.tlb
    SimpleWSTest.dll
    3) Add a " [ClassInterface(ClassInterfaceType.AutoDual)]" attribute to the
    SimpleWSTest class. i.e.
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class SimpleWSTest :
    Microsoft.Web.Services2.WebServicesClientProtocol
    4) Get SimpleWSTest to implement ISimpleWSTest (code appended below) i.e.
    public class SimpleWSTest :
    Microsoft.Web.Services2.WebServicesClientProtocol, ISimpleWSTest
    5) 3 and 1 togeter, 3 and 2 together
    6) 4 and 1 together, 4 and 2 together
    7) Note
    7.1) All other code (e.g. ISimpleOrderData.cs, SimpleOrderData.cs,
    IOrderLine.cs, OrderLine.cs were exclude from the project)
    7.2) Everytime I made a change, I unregister the type library using regasm
    /unregister MyClient.dll
    7.3) I uninstall the assembly from GAC. gacutil -u SimpleWSTest
    7.4) I recompile the code
    7.5) I install the assmembly in GAC. gacutil -i SimpleWSTest.dll
    7.6) I register type library using regasm (as per 1 or 2 above)

    /******************Start of ISimpleWSTest Interface******************/
    using System.Xml.Serialization;
    using System;
    using System.Runtime.InteropServices;

    //namespace MyOrg.web.publications
    //{
    /// <remarks/>
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)]
    public interface ISimpleWSTest
    {
    }
    //}
    /******************End of ISimpleWSTest Interface******************/

    "Patrick" <patlreply.newsgroup.msn.com> wrote in message
    news:OHEOKzhqEHA.3568TK2MSFTNGP10.phx.gbl...
    > /********************Start of SimpleWSTest class********************/
    > using System;
    > using System.Web.Services;
    > using System.Runtime.InteropServices;
    > using System.IO;
    >
    > //namespace MyOrg.web.publications
    > //{
    >
    > [System.Web.Services.WebServiceBindingAttribute(Nam e="iOrderSoap",
    > Namespace="http://localhost/webservice1/")]
    > [System.ComponentModel.DesignerCategoryAttribute("c ode")]
    > public class SimpleWSTest :
    > Microsoft.Web.Services2.WebServicesClientProtocol
    > {
    >
    > public SimpleWSTest()
    > {
    > this.Url = "https://testserver/Order/iOrder.asmx";
    > }
    > }
    > //}
    > /********************End of SimpleWSTest class********************/
    >
    >

    Patrick Guest

  12. #12

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library

    Hi Patrick,

    Can you post the code about IOrder and your web service so that I can
    perform a similar test on my side? With the test, I may find more about the
    problem.

    Thanks,

    Luke

    [MSFT] Guest

  13. #13

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    I have uploaded the code together with VBScript and ASP (not ASP.NET) test
    client, which demo the problems I face in exposing a .NET class library used
    for making web service call to VB/ASP clients via Interop at
    [url]http://www.geocities.com/drkestrel/K3AF30BF8EAECB4AF670/7CE0BD928A91/Order-WebServiceDemo.zip[/url]

    (As this is also an interop related problem, I am cross posting to
    [url]news://msnews.microsoft.com/microsoft.public.dotnet.framework.interop[/url] )

    Note
    1) In order to compile the code, a strong name key need to be placed at
    c:\dev\general\DotNET-MyOrg-StrongNameKey\MyOrg.snk
    2) I am running it on a Windows XP Professional SP1 PC with IIS5.1 (although
    eventually the production environment is likely to be Windows 2000 Server
    SP4 on IIS5.0). On the WinXP box, I am always running as a domain user that
    is a member of the local admin. IIS is set to accept integrated windows
    authentication only and I am logging on as the same domain user.
    3) The assembly were added to GAC:
    gacutil -i webserviceInterop.dll
    4) The type library were registered:
    regasm /tlb:webserviceInterop.tlb webserviceInterop.dll

    A summary of the problems/observations are as follows:
    1) ASP Client can always instantiate with late-binding .NET classes using
    Interop MyOrg.web.publications.SimpleOrderData and
    MyOrg.web.publications.OrderLine but could never instantiate
    MyOrg.web.publications.Order, with the following error. Note in IIS, Only
    Integrated Windows Authentication is turned on, with test user logging on as
    local administrator.
    *****************Start of ASP Error*****************
    Active Server Pages error 'ASP 0115'

    Unexpected error

    /test4.asp

    A trappable error (C0000005) occurred in an external object. The
    script cannot
    continue running.
    *****************End of ASP Error*****************
    2) VBScript can always instantiate with late binding .NET classes using
    Interop MyOrg.web.publications.SimpleOrderData and
    MyOrg.web.publications.OrderLine AND MyOrg.web.publications.Order

    2.1) When the PlaceOrder method of Order class / IOrder interface is set to
    accept a parameter of type SimpleOrderData, when PlaceOrder is invoked from
    VBScript, an error is returned as follows. If PlaceOrder takes a String
    parameter, no error is returned:
    *****************Start of VBScript Error*****************
    Windows Script Host
    Script: C:\temp\test3.vbs
    Line: 26
    Char: 1
    Error: Invalid procedure call or argument: 'PlaceOrder'
    Code: 800A0005
    Source: Microsoft VBScript runtime error
    [OK]
    *****************End of VBScript Error*****************
    3) With the Order.cs file, adding the following attribute instead of
    implementing IOrder interface and excluding IOrder.cs from the Visual Studio
    C# project makes no difference to 1 & 2 above:
    [ClassInterface(ClassInterfaceType.AutoDual)]

    4) Even removing all methods definition from IOrder.cs and Order.cs, ASP
    client can still NOT instantiate the Order class.

    5) registering type library with /codebase switch makes no difference to
    observations 1 and 2 above.

    6) PlaceOrder can be invoked from a .NET client (e.g. a win forms
    application) and behave as expected.

    7) The intention is to expose the MyOrg.web.publications.* to ASP.

    "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    news:yF4LQzqqEHA.3468cpmsftngxa06.phx.gbl...
    > Hi Patrick,
    >
    > Can you post the code about IOrder and your web service so that I can
    > perform a similar test on my side? With the test, I may find more about
    the
    > problem.
    >
    > Thanks,
    >
    > Luke
    >

    Patrick Guest

  14. #14

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    I know I am no where near getting this working, but wondering when I do get
    it working should my ASP pages invoke the webservices (using this .NET class
    library via interop):
    - using the synchronous mode or
    - using the asynchronous mode

    I am confused because:
    - if using synchronous mode, my ASP pages could very easily time out! Can't
    think of how to get around it!
    - if using asynchronous mode, how could my ASP pages get a reply back from
    the EndPlaceOrder method (the ASP pages were to invoke BeginPlaceHolder)?
    Does it "poll" it or something?


    "Patrick" <patlreply.newsgroup.msn.com> wrote in message
    news:uTWQ8msqEHA.3868TK2MSFTNGP15.phx.gbl...
    > I have uploaded the code together with VBScript and ASP (not ASP.NET) test
    > client, which demo the problems I face in exposing a .NET class library
    used
    > for making web service call to VB/ASP clients via Interop at
    >
    [url]http://www.geocities.com/drkestrel/K3AF30BF8EAECB4AF670/7CE0BD928A91/Order-WebServiceDemo.zip[/url]
    >
    > (As this is also an interop related problem, I am cross posting to
    > [url]news://msnews.microsoft.com/microsoft.public.dotnet.framework.interop[/url] )
    >
    > Note
    > 1) In order to compile the code, a strong name key need to be placed at
    > c:\dev\general\DotNET-MyOrg-StrongNameKey\MyOrg.snk
    > 2) I am running it on a Windows XP Professional SP1 PC with IIS5.1
    (although
    > eventually the production environment is likely to be Windows 2000 Server
    > SP4 on IIS5.0). On the WinXP box, I am always running as a domain user
    that
    > is a member of the local admin. IIS is set to accept integrated windows
    > authentication only and I am logging on as the same domain user.
    > 3) The assembly were added to GAC:
    > gacutil -i webserviceInterop.dll
    > 4) The type library were registered:
    > regasm /tlb:webserviceInterop.tlb webserviceInterop.dll
    >
    > A summary of the problems/observations are as follows:
    > 1) ASP Client can always instantiate with late-binding .NET classes using
    > Interop MyOrg.web.publications.SimpleOrderData and
    > MyOrg.web.publications.OrderLine but could never instantiate
    > MyOrg.web.publications.Order, with the following error. Note in IIS, Only
    > Integrated Windows Authentication is turned on, with test user logging on
    as
    > local administrator.
    > *****************Start of ASP Error*****************
    > Active Server Pages error 'ASP 0115'
    >
    > Unexpected error
    >
    > /test4.asp
    >
    > A trappable error (C0000005) occurred in an external object. The
    > script cannot
    > continue running.
    > *****************End of ASP Error*****************
    > 2) VBScript can always instantiate with late binding .NET classes using
    > Interop MyOrg.web.publications.SimpleOrderData and
    > MyOrg.web.publications.OrderLine AND MyOrg.web.publications.Order
    >
    > 2.1) When the PlaceOrder method of Order class / IOrder interface is set
    to
    > accept a parameter of type SimpleOrderData, when PlaceOrder is invoked
    from
    > VBScript, an error is returned as follows. If PlaceOrder takes a String
    > parameter, no error is returned:
    > *****************Start of VBScript Error*****************
    > Windows Script Host
    > Script: C:\temp\test3.vbs
    > Line: 26
    > Char: 1
    > Error: Invalid procedure call or argument: 'PlaceOrder'
    > Code: 800A0005
    > Source: Microsoft VBScript runtime error
    > [OK]
    > *****************End of VBScript Error*****************
    > 3) With the Order.cs file, adding the following attribute instead of
    > implementing IOrder interface and excluding IOrder.cs from the Visual
    Studio
    > C# project makes no difference to 1 & 2 above:
    > [ClassInterface(ClassInterfaceType.AutoDual)]
    >
    > 4) Even removing all methods definition from IOrder.cs and Order.cs, ASP
    > client can still NOT instantiate the Order class.
    >
    > 5) registering type library with /codebase switch makes no difference to
    > observations 1 and 2 above.
    >
    > 6) PlaceOrder can be invoked from a .NET client (e.g. a win forms
    > application) and behave as expected.
    >
    > 7) The intention is to expose the MyOrg.web.publications.* to ASP.
    >
    > "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    > news:yF4LQzqqEHA.3468cpmsftngxa06.phx.gbl...
    > > Hi Patrick,
    > >
    > > Can you post the code about IOrder and your web service so that I can
    > > perform a similar test on my side? With the test, I may find more about
    > the
    > > problem.
    > >
    > > Thanks,
    > >
    > > Luke
    > >
    >
    >

    Patrick Guest

  15. #15

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    HI Patrick,

    Thank you for the code. With it, I reproduce one of your prolem, but not
    with the one in ASP. When I run the VBScript code, I also got the error at
    line

    objIOrderDataClient.PlaceOrder objOnlyOrder

    This is because the parameter's type cannot be recognized when
    late-binding. I changed your code as:

    public void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]SimpleOrderData
    order)

    And then, the error was fixed.

    For MarshalAs Atribute, you may read following article:

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    frlrfSystemRuntimeInteropServicesMarshalAsAttribut eClassTopic.asp
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    l/cpconInteropMarshaling.asp

    However, I cannot reproduce the problem in ASP. The code run soomthly like
    VBScript. One thing worth to mention is I registered with "/codebase":

    regasm /tlb:webserviceInterop.tlb webserviceInterop.dll /codebase

    I think it may still a permission issue or something with the IIS server.
    Did you have another computer can perform the test? I suggest you may
    create a new ASP project on another computer to see what will happened.

    Luke

    [MSFT] Guest

  16. #16

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    Right I have updated IOder.cs and Order.cs to:

    /*****************Start of Code snippet from IOrder.cs*****************/
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    r/webservices/PlaceOrder",
    RequestNamespace="http://testserver/webservices/",
    ResponseNamespace="http://testserver/webservices/",
    Use=System.Web.Services.Description.SoapBindingUse .Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData order)
    ;

    /// <remarks/>
    System.IAsyncResult BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    SimpleOrderData order, System.AsyncCallback callback, object asyncState) ;

    /*****************End of Code snippet from IOrder.cs*****************/



    /******************Start of code snippet from Order.cs******************/


    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    r/webservices/PlaceOrder",
    RequestNamespace="http://testserver/webservices/",
    ResponseNamespace="http://testserver/webservices/",
    Use=System.Web.Services.Description.SoapBindingUse .Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    public void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData
    order)
    {
    try
    {
    String Temp = "";
    EventLog objEventLog = new EventLog();


    Temp += "test of ";
    Temp += System.DateTime.Now.ToString() + "\n";
    Temp += "TestOrder=" + order.TestOrder + "\n";
    Temp += "FirstName" + order.FirstName + "\n";
    Temp += "Surname" + order.Surname + "\n";
    Temp += "order.OrderLines(0).StockCode" + order.OrderLines[0].StockCode
    ;

    objEventLog.Log = "Application";
    objEventLog.Source = ".NET Runtime";

    objEventLog.WriteEntry(Temp,EventLogEntryType.Info rmation);


    //fileStream.WriteLine("" + );
    // this.Invoke("PlaceOrder", new object[] {
    // order});
    }
    catch (Exception ex)
    {
    System.Diagnostics.Trace.WriteLine(ex);
    }
    }

    /// <remarks/>
    public System.IAsyncResult
    BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData order,
    System.AsyncCallback callback, object asyncState)
    {
    return this.BeginInvoke("PlaceOrder", new object[] {
    order}, callback, asyncState);
    }

    /******************End of code snippet from Order.cs******************/

    1) When I execute from VBScript:

    1.1) I get no errors when I call PlaceOrder

    1.2) However, PlaceOrder does *Not* seem to have done what it is supposed to
    have- i.e., log what is in the order SimpleOrderData object into the Event
    Viewer! I execute the VBScript in the context of the user logged on to the
    machine (a local admin on WinXP Pro SP1)

    2) If I run the ASP Script, I still get the same error:

    /*****************************start of ASP
    Error*****************************/

    Active Server Pages error 'ASP 0115'

    Unexpected error

    /test4.asp

    A trappable error (C0000005) occurred in an external object. The script
    cannot continue running


    /*****************************end of ASP Error*****************************/

    3) Note, regasm with /codebase switch does NOT make a difference!

    3.1) Note according to
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfassemblyregistrationtoolregasmexe.asp[/url] ,
    /codebase switch should only be used when the assembly is *not* put in the
    GAC, but I am putting the assembly in the GAC!

    4) Should I call the webservice from ASP using .NET Interop using the
    synchronous mode or asynchronous mode??

    4.1) If using synchronous mode? How could I prevent ASP pages from timing
    out?

    4.2) If using asynchronous mode? How could ASP pages get results back from
    EndPlaceOrder method??



    "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    news:JipT8N4qEHA.2084cpmsftngxa06.phx.gbl...
    > HI Patrick,
    >
    > Thank you for the code. With it, I reproduce one of your prolem, but not
    > with the one in ASP. When I run the VBScript code, I also got the error at
    > line
    >
    > objIOrderDataClient.PlaceOrder objOnlyOrder
    >
    > This is because the parameter's type cannot be recognized when
    > late-binding. I changed your code as:
    >
    > public void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]SimpleOrderData
    > order)
    >
    > And then, the error was fixed.
    >
    > For MarshalAs Atribute, you may read following article:
    >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    > frlrfSystemRuntimeInteropServicesMarshalAsAttribut eClassTopic.asp
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    > l/cpconInteropMarshaling.asp
    >
    > However, I cannot reproduce the problem in ASP. The code run soomthly like
    > VBScript. One thing worth to mention is I registered with "/codebase":
    >
    > regasm /tlb:webserviceInterop.tlb webserviceInterop.dll /codebase
    >
    > I think it may still a permission issue or something with the IIS server.
    > Did you have another computer can perform the test? I suggest you may
    > create a new ASP project on another computer to see what will happened.
    >
    > Luke
    >

    Patrick Guest

  17. #17

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    Note, I am running
    - IIS5.1
    ---- Directory/File Security set to only support integrated windows
    authentication
    ---- when loading test4.asp, Log on from IE6 SP1 using a Domain user account
    that is a member of the local administrator group
    - Windows XP Professional SP1,
    - .NET Framework 1.1 (without the latest Service pack released a week or so
    ago)

    "Patrick" <patlreply.newsgroup.msn.com> wrote in message
    news:uOkeUq6qEHA.2732TK2MSFTNGP09.phx.gbl...
    > Right I have updated IOder.cs and Order.cs to:
    >
    > /*****************Start of Code snippet from IOrder.cs*****************/
    >
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    > r/webservices/PlaceOrder",
    > RequestNamespace="http://testserver/webservices/",
    > ResponseNamespace="http://testserver/webservices/",
    > Use=System.Web.Services.Description.SoapBindingUse .Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    > void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData
    order)
    > ;
    >
    > /// <remarks/>
    > System.IAsyncResult BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    > SimpleOrderData order, System.AsyncCallback callback, object asyncState) ;
    >
    > /*****************End of Code snippet from IOrder.cs*****************/
    >
    >
    >
    > /******************Start of code snippet from Order.cs******************/
    >
    >
    >
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    > r/webservices/PlaceOrder",
    > RequestNamespace="http://testserver/webservices/",
    > ResponseNamespace="http://testserver/webservices/",
    > Use=System.Web.Services.Description.SoapBindingUse .Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    > public void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    SimpleOrderData
    > order)
    > {
    > try
    > {
    > String Temp = "";
    > EventLog objEventLog = new EventLog();
    >
    >
    > Temp += "test of ";
    > Temp += System.DateTime.Now.ToString() + "\n";
    > Temp += "TestOrder=" + order.TestOrder + "\n";
    > Temp += "FirstName" + order.FirstName + "\n";
    > Temp += "Surname" + order.Surname + "\n";
    > Temp += "order.OrderLines(0).StockCode" +
    order.OrderLines[0].StockCode
    > ;
    >
    > objEventLog.Log = "Application";
    > objEventLog.Source = ".NET Runtime";
    >
    > objEventLog.WriteEntry(Temp,EventLogEntryType.Info rmation);
    >
    >
    > //fileStream.WriteLine("" + );
    > // this.Invoke("PlaceOrder", new object[] {
    > // order});
    > }
    > catch (Exception ex)
    > {
    > System.Diagnostics.Trace.WriteLine(ex);
    > }
    > }
    >
    > /// <remarks/>
    > public System.IAsyncResult
    > BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData order,
    > System.AsyncCallback callback, object asyncState)
    > {
    > return this.BeginInvoke("PlaceOrder", new object[] {
    > order}, callback, asyncState);
    > }
    >
    > /******************End of code snippet from Order.cs******************/
    >
    > 1) When I execute from VBScript:
    >
    > 1.1) I get no errors when I call PlaceOrder
    >
    > 1.2) However, PlaceOrder does *Not* seem to have done what it is supposed
    to
    > have- i.e., log what is in the order SimpleOrderData object into the Event
    > Viewer! I execute the VBScript in the context of the user logged on to
    the
    > machine (a local admin on WinXP Pro SP1)
    >
    > 2) If I run the ASP Script, I still get the same error:
    >
    > /*****************************start of ASP
    > Error*****************************/
    >
    > Active Server Pages error 'ASP 0115'
    >
    > Unexpected error
    >
    > /test4.asp
    >
    > A trappable error (C0000005) occurred in an external object. The script
    > cannot continue running
    >
    >
    > /*****************************end of ASP
    Error*****************************/
    >
    > 3) Note, regasm with /codebase switch does NOT make a difference!
    >
    > 3.1) Note according to
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfassemblyregistrationtoolregasmexe.asp[/url] ,
    > /codebase switch should only be used when the assembly is *not* put in the
    > GAC, but I am putting the assembly in the GAC!
    >
    > 4) Should I call the webservice from ASP using .NET Interop using the
    > synchronous mode or asynchronous mode??
    >
    > 4.1) If using synchronous mode? How could I prevent ASP pages from timing
    > out?
    >
    > 4.2) If using asynchronous mode? How could ASP pages get results back
    from
    > EndPlaceOrder method??
    >
    >
    >
    > "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    > news:JipT8N4qEHA.2084cpmsftngxa06.phx.gbl...
    > > HI Patrick,
    > >
    > > Thank you for the code. With it, I reproduce one of your prolem, but not
    > > with the one in ASP. When I run the VBScript code, I also got the error
    at
    > > line
    > >
    > > objIOrderDataClient.PlaceOrder objOnlyOrder
    > >
    > > This is because the parameter's type cannot be recognized when
    > > late-binding. I changed your code as:
    > >
    > > public void
    PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]SimpleOrderData
    > > order)
    > >
    > > And then, the error was fixed.
    > >
    > > For MarshalAs Atribute, you may read following article:
    > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    > > frlrfSystemRuntimeInteropServicesMarshalAsAttribut eClassTopic.asp
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    > > l/cpconInteropMarshaling.asp
    > >
    > > However, I cannot reproduce the problem in ASP. The code run soomthly
    like
    > > VBScript. One thing worth to mention is I registered with "/codebase":
    > >
    > > regasm /tlb:webserviceInterop.tlb webserviceInterop.dll /codebase
    > >
    > > I think it may still a permission issue or something with the IIS
    server.
    > > Did you have another computer can perform the test? I suggest you may
    > > create a new ASP project on another computer to see what will happened.
    > >
    > > Luke
    > >
    >
    >

    Patrick Guest

  18. #18

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    Also, marhsalling the "SimpleOrderData" object as
    [MarshalAs(UnmanagedType.IDispatch)] makes no difference-
    1) Invoke from VBScript as local administrator: nothing get logged in Event
    Viewer as expected from the PlaceOrder method
    2) Invoke from ASP, logging in as local admin using integrated windows
    authentication- still get ASP0115 unexpected error!

    "Patrick" <patlreply.newsgroup.msn.com> wrote in message
    news:uOkeUq6qEHA.2732TK2MSFTNGP09.phx.gbl...
    > Right I have updated IOder.cs and Order.cs to:
    >
    > /*****************Start of Code snippet from IOrder.cs*****************/
    >
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    > r/webservices/PlaceOrder",
    > RequestNamespace="http://testserver/webservices/",
    > ResponseNamespace="http://testserver/webservices/",
    > Use=System.Web.Services.Description.SoapBindingUse .Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    > void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData
    order)
    > ;
    >
    > /// <remarks/>
    > System.IAsyncResult BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    > SimpleOrderData order, System.AsyncCallback callback, object asyncState) ;
    >
    > /*****************End of Code snippet from IOrder.cs*****************/
    >
    >
    >
    > /******************Start of code snippet from Order.cs******************/
    >
    >
    >
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    > r/webservices/PlaceOrder",
    > RequestNamespace="http://testserver/webservices/",
    > ResponseNamespace="http://testserver/webservices/",
    > Use=System.Web.Services.Description.SoapBindingUse .Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    > public void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    SimpleOrderData
    > order)
    > {
    > try
    > {
    > String Temp = "";
    > EventLog objEventLog = new EventLog();
    >
    >
    > Temp += "test of ";
    > Temp += System.DateTime.Now.ToString() + "\n";
    > Temp += "TestOrder=" + order.TestOrder + "\n";
    > Temp += "FirstName" + order.FirstName + "\n";
    > Temp += "Surname" + order.Surname + "\n";
    > Temp += "order.OrderLines(0).StockCode" +
    order.OrderLines[0].StockCode
    > ;
    >
    > objEventLog.Log = "Application";
    > objEventLog.Source = ".NET Runtime";
    >
    > objEventLog.WriteEntry(Temp,EventLogEntryType.Info rmation);
    >
    >
    > //fileStream.WriteLine("" + );
    > // this.Invoke("PlaceOrder", new object[] {
    > // order});
    > }
    > catch (Exception ex)
    > {
    > System.Diagnostics.Trace.WriteLine(ex);
    > }
    > }
    >
    > /// <remarks/>
    > public System.IAsyncResult
    > BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData order,
    > System.AsyncCallback callback, object asyncState)
    > {
    > return this.BeginInvoke("PlaceOrder", new object[] {
    > order}, callback, asyncState);
    > }
    >
    > /******************End of code snippet from Order.cs******************/
    >
    > 1) When I execute from VBScript:
    >
    > 1.1) I get no errors when I call PlaceOrder
    >
    > 1.2) However, PlaceOrder does *Not* seem to have done what it is supposed
    to
    > have- i.e., log what is in the order SimpleOrderData object into the Event
    > Viewer! I execute the VBScript in the context of the user logged on to
    the
    > machine (a local admin on WinXP Pro SP1)
    >
    > 2) If I run the ASP Script, I still get the same error:
    >
    > /*****************************start of ASP
    > Error*****************************/
    >
    > Active Server Pages error 'ASP 0115'
    >
    > Unexpected error
    >
    > /test4.asp
    >
    > A trappable error (C0000005) occurred in an external object. The script
    > cannot continue running
    >
    >
    > /*****************************end of ASP
    Error*****************************/
    >
    > 3) Note, regasm with /codebase switch does NOT make a difference!
    >
    > 3.1) Note according to
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfassemblyregistrationtoolregasmexe.asp[/url] ,
    > /codebase switch should only be used when the assembly is *not* put in the
    > GAC, but I am putting the assembly in the GAC!
    >
    > 4) Should I call the webservice from ASP using .NET Interop using the
    > synchronous mode or asynchronous mode??
    >
    > 4.1) If using synchronous mode? How could I prevent ASP pages from timing
    > out?
    >
    > 4.2) If using asynchronous mode? How could ASP pages get results back
    from
    > EndPlaceOrder method??
    >
    >
    >
    > "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    > news:JipT8N4qEHA.2084cpmsftngxa06.phx.gbl...
    > > HI Patrick,
    > >
    > > Thank you for the code. With it, I reproduce one of your prolem, but not
    > > with the one in ASP. When I run the VBScript code, I also got the error
    at
    > > line
    > >
    > > objIOrderDataClient.PlaceOrder objOnlyOrder
    > >
    > > This is because the parameter's type cannot be recognized when
    > > late-binding. I changed your code as:
    > >
    > > public void
    PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]SimpleOrderData
    > > order)
    > >
    > > And then, the error was fixed.
    > >
    > > For MarshalAs Atribute, you may read following article:
    > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    > > frlrfSystemRuntimeInteropServicesMarshalAsAttribut eClassTopic.asp
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    > > l/cpconInteropMarshaling.asp
    > >
    > > However, I cannot reproduce the problem in ASP. The code run soomthly
    like
    > > VBScript. One thing worth to mention is I registered with "/codebase":
    > >
    > > regasm /tlb:webserviceInterop.tlb webserviceInterop.dll /codebase
    > >
    > > I think it may still a permission issue or something with the IIS
    server.
    > > Did you have another computer can perform the test? I suggest you may
    > > create a new ASP project on another computer to see what will happened.
    > >
    > > Luke
    > >
    >
    >

    Patrick Guest

  19. #19

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    I have updated the demo code as follow:
    [url]http://www.geocities.com/drkestrel/K3AF30BF8EAECB4AF670/7CE0BD928A91/Order-WebServiceDemo.zip[/url]

    (as before, to compile the code, a strong name key file needs to be present
    at C:\dev\general\DotNET-MyOrg-StrongNameKey\MyOrg.snk)

    Added more logging code which demonstrated that
    1) When test\test3.vbs is invoked:
    1.1) The event log logging code is run when CreateObject on
    MyOrg.web.publications.Order is invoked
    1.2) when objIOrderDataClient.PlaceOrder is invoked from VBScript, the Event
    Log logging code in PlaceOrder method does not seem to have run!

    2) When I load test\test4.asp from IIS
    2.1)with
    2.1.1) IIS support Integrated windows authentication, and me logging on as a
    local admin OR
    2.1.2) IUSR_<workstationName> added to Local Administrator group, and
    anonymous access allowed
    2.2) then None of the event log logging code get executed (nothing logged in
    event viewer!)

    "Patrick" <patlreply.newsgroup.msn.com> wrote in message
    news:uOkeUq6qEHA.2732TK2MSFTNGP09.phx.gbl...
    > Right I have updated IOder.cs and Order.cs to:
    >
    > /*****************Start of Code snippet from IOrder.cs*****************/
    >
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    > r/webservices/PlaceOrder",
    > RequestNamespace="http://testserver/webservices/",
    > ResponseNamespace="http://testserver/webservices/",
    > Use=System.Web.Services.Description.SoapBindingUse .Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    > void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData
    order)
    > ;
    >
    > /// <remarks/>
    > System.IAsyncResult BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    > SimpleOrderData order, System.AsyncCallback callback, object asyncState) ;
    >
    > /*****************End of Code snippet from IOrder.cs*****************/
    >
    >
    >
    > /******************Start of code snippet from Order.cs******************/
    >
    >
    >
    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    > r/webservices/PlaceOrder",
    > RequestNamespace="http://testserver/webservices/",
    > ResponseNamespace="http://testserver/webservices/",
    > Use=System.Web.Services.Description.SoapBindingUse .Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    > public void PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]
    SimpleOrderData
    > order)
    > {
    > try
    > {
    > String Temp = "";
    > EventLog objEventLog = new EventLog();
    >
    >
    > Temp += "test of ";
    > Temp += System.DateTime.Now.ToString() + "\n";
    > Temp += "TestOrder=" + order.TestOrder + "\n";
    > Temp += "FirstName" + order.FirstName + "\n";
    > Temp += "Surname" + order.Surname + "\n";
    > Temp += "order.OrderLines(0).StockCode" +
    order.OrderLines[0].StockCode
    > ;
    >
    > objEventLog.Log = "Application";
    > objEventLog.Source = ".NET Runtime";
    >
    > objEventLog.WriteEntry(Temp,EventLogEntryType.Info rmation);
    >
    >
    > //fileStream.WriteLine("" + );
    > // this.Invoke("PlaceOrder", new object[] {
    > // order});
    > }
    > catch (Exception ex)
    > {
    > System.Diagnostics.Trace.WriteLine(ex);
    > }
    > }
    >
    > /// <remarks/>
    > public System.IAsyncResult
    > BeginPlaceOrder([MarshalAs(UnmanagedType.IUnknown)] SimpleOrderData order,
    > System.AsyncCallback callback, object asyncState)
    > {
    > return this.BeginInvoke("PlaceOrder", new object[] {
    > order}, callback, asyncState);
    > }
    >
    > /******************End of code snippet from Order.cs******************/
    >
    > 1) When I execute from VBScript:
    >
    > 1.1) I get no errors when I call PlaceOrder
    >
    > 1.2) However, PlaceOrder does *Not* seem to have done what it is supposed
    to
    > have- i.e., log what is in the order SimpleOrderData object into the Event
    > Viewer! I execute the VBScript in the context of the user logged on to
    the
    > machine (a local admin on WinXP Pro SP1)
    >
    > 2) If I run the ASP Script, I still get the same error:
    >
    > /*****************************start of ASP
    > Error*****************************/
    >
    > Active Server Pages error 'ASP 0115'
    >
    > Unexpected error
    >
    > /test4.asp
    >
    > A trappable error (C0000005) occurred in an external object. The script
    > cannot continue running
    >
    >
    > /*****************************end of ASP
    Error*****************************/
    >
    > 3) Note, regasm with /codebase switch does NOT make a difference!
    >
    > 3.1) Note according to
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfassemblyregistrationtoolregasmexe.asp[/url] ,
    > /codebase switch should only be used when the assembly is *not* put in the
    > GAC, but I am putting the assembly in the GAC!
    >
    > 4) Should I call the webservice from ASP using .NET Interop using the
    > synchronous mode or asynchronous mode??
    >
    > 4.1) If using synchronous mode? How could I prevent ASP pages from timing
    > out?
    >
    > 4.2) If using asynchronous mode? How could ASP pages get results back
    from
    > EndPlaceOrder method??
    >
    >
    >
    > "[MSFT]" <lukezhanonline.microsoft.com> wrote in message
    > news:JipT8N4qEHA.2084cpmsftngxa06.phx.gbl...
    > > HI Patrick,
    > >
    > > Thank you for the code. With it, I reproduce one of your prolem, but not
    > > with the one in ASP. When I run the VBScript code, I also got the error
    at
    > > line
    > >
    > > objIOrderDataClient.PlaceOrder objOnlyOrder
    > >
    > > This is because the parameter's type cannot be recognized when
    > > late-binding. I changed your code as:
    > >
    > > public void
    PlaceOrder([MarshalAs(UnmanagedType.IUnknown)]SimpleOrderData
    > > order)
    > >
    > > And then, the error was fixed.
    > >
    > > For MarshalAs Atribute, you may read following article:
    > >
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    > > frlrfSystemRuntimeInteropServicesMarshalAsAttribut eClassTopic.asp
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    > > l/cpconInteropMarshaling.asp
    > >
    > > However, I cannot reproduce the problem in ASP. The code run soomthly
    like
    > > VBScript. One thing worth to mention is I registered with "/codebase":
    > >
    > > regasm /tlb:webserviceInterop.tlb webserviceInterop.dll /codebase
    > >
    > > I think it may still a permission issue or something with the IIS
    server.
    > > Did you have another computer can perform the test? I suggest you may
    > > create a new ASP project on another computer to see what will happened.
    > >
    > > Luke
    > >
    >
    >

    Patrick Guest

  20. #20

    Default Re: Cannot instantiate .NET Class Library to expose webservice client library via Interop

    Hi Patrick,

    I suggest synchronous mode when calling the web service. When a user browse
    your asp, he would expect a real result even a "time out" message. With
    asynchronous mode, the asp will return to customer without result. We even
    cannot push the result to the customer if he didn't request again.

    Back to the original problem, I modify some of your code and make it run on
    my server finally. There is four event logs recorded and last one is:

    test of 2004-10-7 16:29:38
    TestOrder=True
    FirstNameMickey
    SurnameMouse
    order.OrderLines(0).StockCodeA123


    First in Order.cs:

    ///

    [System.Web.Services.Protocols.SoapDoentMethodAt tribute("http://testserve
    r/webservices/PlaceOrder",
    RequestNamespace="http://testserver/webservices/",
    ResponseNamespace="http://testserver/webservices/",
    Use=System.Web.Services.Description.SoapBindingUse .Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
    public void PlaceOrder([MarshalAs(UnmanagedType.IDispatch)]
    SimpleOrderData order)
    {
    EventLog objEventLog = new EventLog();
    try
    {
    objEventLog.Log = "Application";
    objEventLog.Source = ".NET Runtime";

    objEventLog.WriteEntry("\nPlaceOrder
    invoked\n",EventLogEntryType.Information);
    String Temp = "";
    ...

    I change the marshal type to IDispatch and add the eventlog's Source.

    SimpleOrderData.cs:

    [System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://testserver/webs
    ervices/")]
    public class SimpleOrderData : ISimpleOrderData
    {
    public SimpleOrderData()
    {

    OrderLines= new OrderLine[1];
    }


    /// <remarks/>
    public System.Guid CorrelationID;

    /// <remarks/>
    public string Endpoint;

    /// <remarks/>
    public bool TestOrder;

    /// <remarks/>
    public string Title;

    /// <remarks/>
    public string FirstName;

    /// <remarks/>
    public string Surname;

    /// <remarks/>
    public string AccountName;

    /// <remarks/>
    public string Address1;

    /// <remarks/>
    public string Address2;

    /// <remarks/>
    public string Address3;

    /// <remarks/>
    public string Address4;

    /// <remarks/>
    public string Address5;

    /// <remarks/>
    public string PostCode;

    /// <remarks/>
    public string CustomerCountryCode;

    /// <remarks/>
    public string ShipName;

    /// <remarks/>
    public OrderLine[] OrderLines;

    public void AddOrderLine([MarshalAs(UnmanagedType.IDispatch)] OrderLine o)
    {
    OrderLines[0]=o;
    }

    }
    }

    I add a method AddOrderLine so that there is no array marshal. This may
    cause some problems. I suggest you may use a collection here instead of
    array.

    In the VBScript:

    'objOnlyOrder.OrderLines = arOrderLines
    objOnlyOrder.AddOrderLine(objOnlyOrderLine)

    And the ASP page code:

    <% Language = "VBScript" %>
    <%
    Dim objITwoTenDataClient,objOnlyOrderLine,objOnlyOrder
    Dim arrOrderLines(1)
    %>
    DEBUG 1<br>
    <%
    Set objOnlyOrderLine = CreateObject("MyOrg.web.publications.OrderLine")
    %>
    DEBUG 2<br>
    <%

    Set objOnlyOrder =
    CreateObject("MyOrg.web.publications.SimpleOrderDa ta")
    %>
    DEBUG 3- ASP code will fail on the following line:<br>
    Set objITwoTenDataClient = CreateObject("MyOrg.web.publications.Order")<br>
    <%

    Set objITwoTenDataClient = CreateObject("MyOrg.web.publications.Order")
    %>
    DEBUG 4<br>
    <%


    objOnlyOrderLine.StockCode = "A123"
    objOnlyOrderLine.Quantity = 2
    %>
    DEBUG 5<br>
    <%

    objOnlyOrder.TestOrder = true
    objOnlyOrder.FirstName = "Mickey"
    objOnlyOrder.Surname = "Mouse"
    %>
    DEBUG 6<br>
    <%

    'objOnlyOrder.OrderLines = arOrderLines
    objOnlyOrder.AddOrderLine(objOnlyOrderLine)
    %>
    DEBUG 7<br>
    <%

    objITwoTenDataClient.PlaceOrder objOnlyOrder
    %>
    DEBUG 8

    Notice some "set" words have been removed. And Here is the Page I got:

    DEBUG 1
    DEBUG 2
    DEBUG 3- ASP code will fail on the following line:
    Set objITwoTenDataClient = CreateObject("MyOrg.web.publications.Order")
    DEBUG 4
    DEBUG 5
    DEBUG 6
    DEBUG 7
    DEBUG 8

    You may try to test my code to see if it can work on your side. Before you
    rebuild the project, you can first remove the componet from GAC. After the
    rebuliding, register it again with gacutil and regasm, and reset IIS.

    Luke

    [MSFT] Guest

Page 1 of 2 12 LastLast

Similar Threads

  1. http, library loaded, httpS library can't be found
    By DeadWisdom in forum PERL Modules
    Replies: 0
    Last Post: November 8th, 04:51 PM
  2. Webservice from class library
    By Dino Chiesa [Microsoft] in forum ASP.NET Web Services
    Replies: 0
    Last Post: May 13th, 02:59 PM
  3. Replies: 1
    Last Post: August 18th, 10:51 PM
  4. ~/Library/ vs ~/System/Library vs /User/Library/
    By Doug Brown in forum Mac Applications & Software
    Replies: 8
    Last Post: July 20th, 11:56 PM
  5. Replies: 0
    Last Post: July 9th, 07:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139