Calling COM+ in a WebService

D

Daryl Davis

Can I get a sample on how to call a com+ componant in a webservice, please?
This is what I have so far and I am getting an error
Run-time exception thrown : System.NullReferenceException - Object reference
not set to an instance of an object.

Imports System.Web.Services

Imports System.Runtime.InteropServices

<WebMethod()> _

Public Function GetRegKey() As String

Dim obj As Object

obj = CreateObject("hallconfigs.clsconfigs", "192.168.10.1")

Return obj.GetRegKey

End Function
 
D

Daryl Davis

Ok, so your as blunt as a rusty sword, go for a tree trunk.
I am searching through the msdn and I am unable to figure out (might just be
early) how to get this to work with a server components.
Daryl

"Stuart Hemming (via DFN-CIS NetNews Service)"
On 11/06/2004, around 08:55, Daryl Davis wrote:

DD> Can I get a sample on how to call a com+ componant in a webservice,
please?
Forgive me if I sound blunt, but you're doing it wrong. If you have
MSDN on you machine go to Visual Studio .Net|Visual Basic and Visual
C#|Programming with Components|COM Interoperability. Failing that,
there's a tutorial starting at the page pointed to on the link below.

http://msdn.microsoft.com/library/d.../html/vcwlkCOMInteropPart1CClientTutorial.asp
 
D

Daryl Davis

I wish it did. I can call Dlls fine, except from a WebService...
I tried imitating your code and that did not help me either.
Daryl
"Stuart Hemming (via DFN-CIS NetNews Service)"
On 11/06/2004, around 13:36, Daryl Davis wrote:

DD> Ok, so your as blunt as a rusty sword, go for a tree trunk.
DD> I am searching through the msdn and I am unable to figure out (might
just be
DD> early) how to get this to work with a server components.
FWIW, here's what I did.

I'm developing on a machine that has the server components on it so
YMMV.

In you VS project right click on 'References' on the project explorer
and select 'Add Reference'. When the dialog box opens, select the
'COM' tab and pick the COM server you're after. Click 'OK'. When the
machine has finished clicking and wrrring you should have a reference
named for your COM server.

Add a 'using' clause you get the thing recognised in your code and
you're away. Here's a simple example of my code accessing a COM server
called ECS ...

public XmlDocument InputValidation(XmlDocument ChangedValues) {
XmlDocument xmlDoc = new XmlDocument();
Ecs.EcsApplicationClass thisEcs;

thisEcs.Define("ecs-process", "input-validation");
thisEcs.InputText = ChangedValues.OuterXml;
thisEcs.RunProcess();

if (thisEcs.OutputText != null && thisEcs.OutputText != "") {
xmlDoc.LoadXml(thisEcs.OutputText);
// ...
}
return xmlDoc;
}
public void Logout() {
Ecs.EcsApplicationClass thisEcs;
if (Session["ecs"] != null) {
thisEcs = (Ecs.EcsApplicationClass)Session["ecs"];
Marshal.ReleaseComObject(thisEcs);
Session.Clear();
}
}

EcsApplicationClass is the constructor if you like, Define, and
RunProcess are methods, InputText and OutputText are properties. Not
that in Logout you have to call Marshal.ReleaseComObject else the
object remains on the server.

I hope this helps.
 
D

Daryl Davis

You want info, Ill give you info :), Although at this point I am wondering
if it is a bug, because everything I read says this is the way it works.

The com object is a V6 dll sitting on a server. This dll is used to access
SQL database located on the same server.

here is my code on my webservice
<WebMethod()> _

Public Function GetRegKey() As String

Dim obj1 As hallconfigs.clsConfigs

Try

obj1 = CreateObject("hallconfigs.clsconfigs", "192.168.10.254")

Return obj1.GetRegKey 'returns a simple string

Catch ex As Exception

Return 0

End Try

End Function

"Stuart Hemming (via DFN-CIS NetNews Service)"
On 14/06/2004, around 09:10, Daryl Davis wrote:

DD> I wish it did. I can call Dlls fine, except from a WebService...
DD> I tried imitating your code and that did not help me either.

You're gonna have to give me some more info.

For example, what's the COM object?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top