Problems using RPC

T

Tobias Schröer

Hi,

I am running into problems when performing an RPC call on a COM object
via Type.InvokeMember (.Net 2.0 Framework). The exception thrown is
"HRESULT: 0x800706BE", which, after some googling, leads me to this MS
Support Page:
http://support.microsoft.com/?scid=kb;en-us;329080&x=6&y=12

Problem is, this page refers to WIN XP, whereas both my development and
production machines are W2k3 Servers (SP2, latest patch level). On the
development machine the program works perfectly fine. On the production
machine I get the error above.

My program is a Windows service, which fetches data from a COM
application (here the RPC call fails) and writes it to a SQL database.

Does anyone experienced the same and/or has a good suggestion to solve this?

Thanks,
Tobi
 
N

Nicholas Paldino [.NET/C# MVP]

Tobias,

How are you getting the Type instance to make the remote call?
 
T

Tobias Schröer

Sorry,

I should have added some code. Here it comes:

<code>

// get application type
Type appType = Type.GetTypeFromProgID("Prog.Id");
// app instance
object app = Activator.CreateInstance(appType);

// app database object
object appDb = amAppType.InvokeMember(
"Database",
BindingFlags.InvokeMethod,
null,
app,
null);

// app databasee type
Type dbType = amDb.GetType();

// set database name
dbType.InvokeMember(
"Name",
BindingFlags.PutDispProperty,
null,
appDb,
new object[] { "DatabaseName" });

// list of found objects
this._objectList = new List<MyObject>();

// constrain search
string whereClause = "myValue > 0";

// search first record
int retVal = (Int32)dbType.InvokeMember(
"FindFirst",
BindingFlags.InvokeMethod,
null,
appDb,
new object[] { whereClause });

// loop, while records found
while (retVal == 1) {
// create object
MyObject obj = new MyObject();
// get data
obj.MyProperty = (string)dbType.InvokeMember(
"GetContentsByName",
BindingFlags.InvokeMethod,
null,
amDb,
new object[] { "MyPropertyFieldName" });
// add to list
this._objectList.Add(obj);

// get next
retVal = (Int32)dbType.InvokeMember(
"FindNext",
BindingFlags.InvokeMethod,
null,
appDb,
null);
}

</code>
 
N

Nicholas Paldino [.NET/C# MVP]

Tobias,

How is this set up to be called on a remote machine? Do you have a
proxy installed on the local machine in COM+ which has a program id of
"Prog.Id"? If not, then you should be calling the overload of
GetTypeFromProgID which takes the name of the machine which you want to make
the remote call to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tobias Schröer said:
Sorry,

I should have added some code. Here it comes:

<code>

// get application type
Type appType = Type.GetTypeFromProgID("Prog.Id");
// app instance
object app = Activator.CreateInstance(appType);

// app database object
object appDb = amAppType.InvokeMember(
"Database",
BindingFlags.InvokeMethod,
null,
app,
null);

// app databasee type
Type dbType = amDb.GetType();

// set database name
dbType.InvokeMember(
"Name",
BindingFlags.PutDispProperty,
null,
appDb,
new object[] { "DatabaseName" });

// list of found objects
this._objectList = new List<MyObject>();

// constrain search
string whereClause = "myValue > 0";

// search first record
int retVal = (Int32)dbType.InvokeMember(
"FindFirst",
BindingFlags.InvokeMethod,
null,
appDb,
new object[] { whereClause });

// loop, while records found
while (retVal == 1) {
// create object
MyObject obj = new MyObject();
// get data
obj.MyProperty = (string)dbType.InvokeMember(
"GetContentsByName",
BindingFlags.InvokeMethod,
null,
amDb,
new object[] { "MyPropertyFieldName" });
// add to list
this._objectList.Add(obj);

// get next
retVal = (Int32)dbType.InvokeMember(
"FindNext",
BindingFlags.InvokeMethod,
null,
appDb,
null);
}

</code>
Tobias,

How are you getting the Type instance to make the remote call?
 
T

Tobias Schröer

Hi,

I think I mixed up the terms a little. RPC was mentioned in the MS
article I've in in the original post. I was confused about that myself.

The application I want to call via _COM automation_ is installed on the
same server as my service. No remote machines involved.

Tobi
 
W

Willy Denoyette [MVP]

Tobias Schröer said:
Sorry,

I should have added some code. Here it comes:

<code>

// get application type
Type appType = Type.GetTypeFromProgID("Prog.Id");
// app instance
object app = Activator.CreateInstance(appType);

// app database object
object appDb = amAppType.InvokeMember(
"Database",
BindingFlags.InvokeMethod,
null,
app,
null);

// app databasee type
Type dbType = amDb.GetType();

// set database name
dbType.InvokeMember(
"Name",
BindingFlags.PutDispProperty,
null,
appDb,
new object[] { "DatabaseName" });

// list of found objects
this._objectList = new List<MyObject>();

// constrain search
string whereClause = "myValue > 0";

// search first record
int retVal = (Int32)dbType.InvokeMember(
"FindFirst",
BindingFlags.InvokeMethod,
null,
appDb,
new object[] { whereClause });

// loop, while records found
while (retVal == 1) {
// create object
MyObject obj = new MyObject();
// get data
obj.MyProperty = (string)dbType.InvokeMember(
"GetContentsByName",
BindingFlags.InvokeMethod,
null,
amDb,
new object[] { "MyPropertyFieldName" });
// add to list
this._objectList.Add(obj);

// get next
retVal = (Int32)dbType.InvokeMember(
"FindNext",
BindingFlags.InvokeMethod,
null,
appDb,
null);
}

</code>
Tobias,

How are you getting the Type instance to make the remote call?



Where exactly is the exception thrown?

Willy.
 
N

Nicholas Paldino [.NET/C# MVP]

Tobias,

Ok, so if it is on the local machine, and you aren't running it out of
process (through COM+), then which call to InvokeMember is giving you the
problem?

Also, is the method only able to be called through a late bound call?
Any way you can get an interface definition in there which is early bound?
 
W

Willy Denoyette [MVP]

Nicholas Paldino said:
Tobias,

Ok, so if it is on the local machine, and you aren't running it out of
process (through COM+), then which call to InvokeMember is giving you the
problem?

Also, is the method only able to be called through a late bound call?
Any way you can get an interface definition in there which is early bound?

The OP said the DCOM server was an "automation server", the HRESULT code
indicates he has a security issue.

Willy.
 
W

Willy Denoyette [MVP]

Tobias Schröer said:
Hi,

I think I mixed up the terms a little. RPC was mentioned in the MS article
I've in in the original post. I was confused about that myself.

The application I want to call via _COM automation_ is installed on the
same server as my service. No remote machines involved.

Tobi


What's the account the service is running in, and what kind of "automation
server" is this, a windows (UI) or a non windows application.

Willy.
 
T

Tobias Schröer

Hi,
What's the account the service is running in, and what kind of
"automation server" is this, a windows (UI) or a non windows application.

The account is the local administrator (not good, I know. I change this
as soon as i get the service running). So access rights should not be
the problem here.
The application I call is a WinApp but opens no UI. As said, on my
development machine the service runs. But you gave me a point to think
about. If configured wrong (e.g. the DB name) the applications opens an
error popup, which will not be allowed in a service. I'll have a look at
this, thanks.

Tobi
 
W

Willy Denoyette [MVP]

Tobias Schröer said:
Hi,


The account is the local administrator (not good, I know. I change this as
soon as i get the service running). So access rights should not be the
problem here.
The application I call is a WinApp but opens no UI. As said, on my
development machine the service runs. But you gave me a point to think
about. If configured wrong (e.g. the DB name) the applications opens an
error popup, which will not be allowed in a service. I'll have a look at
this, thanks.

Tobi


But this is an out-proc automation server, the error pop-up can only be an
issue after you have connected to the server and called a method, however
you don't get that far yet.
The issue you have, is at the launch or access level, so you should watch
the DCOM security settings on your system, DCOMCNFG is your friend for now,
you should also look at the security log.

Willy.
 
T

Tobias Schröer

Hi,

thanks for your help so far. During the weekend I installed a
missing/new (?) .Net Patch (came through Windows update) and: I works.
Don't know why, but it does :)

Thanks anyway,
Tobi
 

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

Top