centrop67

I have poked around (searched) the forum for an answer to this, but, though some situations are close, I have yet to find one that matches or actually solves my problem.

I am trying to access an ActiveX DLL from web services. This works on my development box without a problem using the interop dll created when I add the reference. However, when I copy the files over to the server (Windows 2003), the instances of the dll don't seem to be aligned.

That is, I get an object (no errors) but it's not the right one, because it shouldn't have a value of nothing.

BTW - this also works on the server if I do an application type project versus a website type project.

I have moved the use of the ActiveX dll from the web service class to a .NET class to a VB6 class with the same results.

Code Info - the imports are the ActiveX DLLs I need to access. oHosts.UIActiveSession should provide a link to the application I need to access and is only nothing from the web service. If I create a Windows Application that uses HostTest it runs fine on the server.

I could be wrong but this doesn't seem difficult OR different from what a lot of other developers are facing with solutions that use the older technology. Right

Thanks in advance for any help.

Michael

<WebMethod()> _

Public Function GetZPP(ByVal RecLoc As String) As String

Dim o As New ClassLibrary1.HostTest

Dim s As String

s = o.GetZPP(RecLoc)

Return s

End Function

'ClassLibrary1.HostTest:

Imports k1aHostConstantsLib

Imports k1aHostInterface

Imports k1aHostToolKit

Public Class HostTest

Public Function GetZPP(ByVal RLoc As String) As String

Dim oHosts As New HostSessions

Dim oHost As New HostSession

Dim sResponse As String

Dim oResponse As HostResponse

sResponse = "INIT"

Try

sResponse = "Before UIActiveSession"

oHost = oHosts.UIActiveSession

sResponse = "After UIActiveSession" & CStr(oHosts.Count)

oHost.SendSpecialKey(322)

sResponse = "After Send Special Key"

oResponse = oHost.Send("RT" & RLoc)

sResponse = "After Host Send"

oHost = Nothing

oHosts = Nothing

sResponse = oResponse.Text

Catch ex As Exception

sResponse = sResponse & "|" & ex.Message & vbCrLf & vbCrLf & ex.StackTrace & vbCrLf & vbCrLf & ex.Source

Finally

oHost = Nothing

oHosts = Nothing

oResponse = Nothing

End Try

Return sResponse

End Function

Public Sub New()

End Sub

End Class




Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

John Saunders

Suggestion: don't use a web site type project. That's for toy projects, not for real projects that use things like ActiveX DLLs.

For those with short memories, this is the perfect example that Microsoft can make mistakes.

[For those with longer memories, there's Microsoft Bob. ]






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

This response is more confusing than my post. Maybe you could tell me how to create a .Net web service without using a web service project in VS2005.

It looks like I am going to have to revert to Soap3.0 web service. ugghh!






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

John Saunders

Why would you have to revert to the SOAP Toolkit Here's the process, and it's very simple.

  1. Start Visual Studio 2005
  2. Choose File->New->Project
  3. In the Project Types pane, click "VIsual C#" and then in the Templates Pane, choose "ASP.NET Web Service Application"
  4. Click "Ok"

You're done.






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

So you are telling me to try C# instead of Visual Basic That's the only difference between what you suggest and what I am already doing.

Actually, I am going to try that next, but I am not sure what difference the languages will make. Someone here at work mentioned that they actually fixed a nagging problem by using C# instead of VB.

My issue is that the legacy ActiveX DLL I need to use doesn't work as expected when I use it from the web services. It works fine any other way I implement it using .Net, just not from a web service.

I am pretty sure this is a security issue, but I can't seem to pinpoint the failure despite lots of full permissions for NETWORK SERVICE on the server.

Maybe someone with some server administration experience can give me a tip on tracing the problem or setting the right permission.

Thanks MH






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

John Saunders

I really shouldn't answer posts that time of night (or morning).

First, I wasn't suggesting you switch to C#. I actually didn't look at your code, since it didn't seem relevant to the problem you described.

As I look back on it now, the reason it didn't seem relevant is that you didn't describe the problem very well. Which object was Nothing What should it have been

BTW, ASMX web services are multi-threaded. Each request will be serviced on a separate thread. While it may not be the problem you're having now, you should make sure that your DLL is able to run in a multi-threaded environment. Many legacy DLLs expected to be running in a standard Windows application, and don't do well in a web service.






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

Suppose the ActiveX DLL cannot be setup for multi threading.

Is there a way to allow the Web Service to still use it as in forcing the MTA to a Single threaded process

Why would the application work while debugging from VS2005 - I suppose the Development Server used in debugging is single-threaded Can you debug using IIS

You might be on to something here with the threading, I am just not sure what I can do to get around it.

Thanks for your assistance thus far. MH






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

John Saunders

If the code is not thread-safe, then it's not thread-safe, and you'd better not call it from a web service.

Assuming you can't get the authors to fix their code for this environment (or to rewrite in managed code), then you should consider creating a separate server for that DLL and communicating between the Web Service and this separate service using .NET Remoting. In effect, you'll need to make sure that the DLL is only ever accessed from a single thread, from the time it's initialized, through all of the calls, to the time it is uninitialized.

Still, let's not get ahead of ourselves on the threading. You still haven't told me exactly what the problem is - what variable is being set to Nothing when you expected it to be set to something else






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

From the code, oHosts is the variable that isn't referencing the correct object. And I say it this way, because there is no error generated. The object should contain an oHost object in the UIActiveSession property, but it contains nothing.

It has an oHost object if I debug the code, and It does if I run the code in a Windows Application. It only has a problem when run from the Web Service application.

I've been thinking the problem has been security all along, but I really think you hit on something with the threading. The dll is an API, in effect, to a custom application that must be running in order for the oHosts (k1aHostToolkit.HostSessions) object to contain an oHost (k1aHostToolKit.HostSession).

I've gone as far as creating a wrapper ActiveX DLL that uses late binding to instantiate the k1aHostToolkit objects. I get the same result. It does call the wrapper dll and it's functions without any issues. It's just when it goes to get that HostSessions object it doesn't work.

My company created the dll, but there's no way I am going to get support on it.

Can you give me a hint on how to do this service using remoting, otherwise as I said earlier I may have to revert to a SOAP 3.0 web service coded using VB6, and I am not even sure that will work at this point.

Thanks again.

Simplified Code:

<WebMethod()> _

Public Function HostSend(ByVal Cmd As String) As String

Dim oHosts As New k1aHostToolKit.HostSessions

Dim oHost As k1aHostToolKit.HostSession

Dim sReturn As String

sReturn = ""

Try

oHost = oHosts.UIActiveSession '<- Problem Area (Here or in declaration)

oHost.Send(Cmd)

sReturn = "<WEBSERVICE_RESPONSE><![CDATA["

sReturn = sReturn & oHost.LastResponse.Text

sReturn = sReturn & "]]></WEBSERVICE_RESPONSE>"

Catch ex As Exception

sReturn = "<WEBSERVICE_ERROR><![CDATA["

sReturn = sReturn & ex.Message

sReturn = sReturn & " | " & ex.StackTrace

sReturn = sReturn & " | " & ex.Source

sReturn = sReturn & "]]></WEBSERVICE_ERROR>"

End Try

Return sReturn

End Function






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

Uggggghhhhhh! The SOAP30 web service produced the same results!






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

So a co-worker has beaten me to a fix on this issue. It was the threading issue. He told me that he was able to start a thread and make calls to the object over the thread. I will post a more specific answer when I get in to work tomorrow.

As a long, long, long-time VB programmer, threading is rarely an issue for me, even though I can grasp the concept.

Thanks John for putting up with me as I worked through this. MH






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

John Saunders

Hey, no problem at all. I'm glad that you and your coworker are solving the problem.

The take-away lesson from this is that we tend to think of ".NET vs. Native" as being the big distinction; that once we get a piece of native code to be callable from .NET code, the job is over. We (and I really do mean we) tend to try calling the native code from a Windows Forms application, or a console application, or maybe from a unit test framework. If it works, we go ahead and start calling it from an ASP.NET Web Application or Web Service.

But there's a big difference between a Windows Forms application and an ASP.NET application or web service: threads. These applications will handle each request on a different thread. The problem of course is that, as you say, you can program VB6 for years and never need to worry about threads. The same goes for most C/C++ code. The result is that code that "works" in a single-threaded environment may not do so well in a multi-threaded environment.

It really shouldn't be surprising, as the original native code probably didn't have "operate in a multi-threaded managed code environment" as one of its requirements.






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

centrop67

As a follow-up, the threading is probably the problem, but the work-around my co-worker created did NOT work, either. I also found out that I have the same issue when I try to use the object from a Windows Service.

I had to implement this application with queues to get the results I needed. It's a complete hack, but it's only a temporary solution while my customer migrates to our real web service solution. MH






Re: ASMX Web Services and XML Serialization ActiveX Dll access from Web Services

John Saunders

I'm glad you found a workaround. I almost mentioned using queues (MSMQ), but if you don't use them elsewhere in your application, I felt that would be overkill.

BTW, be sure when you test, to test on a multi-CPU (or dual core) system. I've seen it really make a difference.