Archived
This forum has been archived. Please start a new discussion on GitHub.
Ice::NoObjectFactoryException
Hello,
I my slice definition I've created a sequence, that contains Test objects. In this class there is a function, which returns the 'TestSequence':
class Test;
sequence<Test> TestSequence;
class Test
{
TestSequence op();
};
The client invokes the function as follows:
TestSequence test = new TestSequence;
test = testProxy->op();
The server executes the function call:
TestSequence TestI::op()
{
TestSequence testSeq = new TestSequence;
...
TestPtr obj = new TestI();
testSeq.push_back(obj);
...
return testSeq;
}
If I run my application I get the following error message:
Test.cxx: Ice::NoObjectFactoryException:
protocol error: no suitable object factory found for '::Test'
I don't know where the problem lies. Can you help me out?
Thanks
I my slice definition I've created a sequence, that contains Test objects. In this class there is a function, which returns the 'TestSequence':
class Test;
sequence<Test> TestSequence;
class Test
{
TestSequence op();
};
The client invokes the function as follows:
TestSequence test = new TestSequence;
test = testProxy->op();
The server executes the function call:
TestSequence TestI::op()
{
TestSequence testSeq = new TestSequence;
...
TestPtr obj = new TestI();
testSeq.push_back(obj);
...
return testSeq;
}
If I run my application I get the following error message:
Test.cxx: Ice::NoObjectFactoryException:
protocol error: no suitable object factory found for '::Test'
I don't know where the problem lies. Can you help me out?
Thanks
0
Comments
-
If you want to transfer "Test" objects by-value, then you must install an object factory for "TestI" in the client, so that Ice knows how to instantiate new Test objects when unmarshaling.
For an example, have a look at demo/Ice/value. In the file Client.cpp, you'll find the following code:
Ice::ObjectFactoryPtr factory = new ObjectFactory;
communicator->addObjectFactory(factory, "::Printer");
You can take this as an example for how to install object factories for by-value transfer of objects.0 -
Thanks for your fast reply.
Another question, is there any possibility to transfer objects by reference? If yes, how can I implement it in my testcase?0 -
Sure, that's called "by proxy". (We try to avoid the term "reference", because it is so ambiguous.)
Sending a proxy for an object instead of the object by value is much more common. Please see the Ice documentation for more information, it has lots of examples for by-proxy transfer.0 -
After I had a look at the demo programs, I have changed my example to 'by proxy' transfer. In my client I invoke a function as remote call. In the server the function is executed and send back a proxy [TestSequence - Object] to the client.
Slice:
****
class Test;
sequence<Test> TestSequence;
class Test
{
void op(out TestSequence testSeq);
};
Client:
*****
Ice::ObjectFactoryPtr factory = new ObjectFactory;
communicator->addObjectFactory(factory, "::Test");
TestSequence *testObject = new TestSequence;
proxy->op(*testObject);
Server:
******
void TestI::op(TestSequence &testSeq, const Ice::Current&)
{
...
TestPtr obj = new TestI();
testSeq.push_back(obj);
...
}
While executing my application I get the following message:
server: error: unknown exception in 'Ice.ThreadPool.Server'
I think it's only a small problem, but I can't see it.0 -
This is still by-value transfer. If you want by-proxy transfer, you would have to change:
sequence<Test> TestSequence;
To:
sequence<Test*> TestSequence;
As for the exception, I'm afraid I don't know where this is coming from. Do you have a stack trace?
Also note that you don't need an object factory for by-proxy transfer.0 -
Thanks, now it works fine.
I followed your hint and changed some minor problems.
I've read it in the documentation, that I don't need an object factory, but it seems I forgot it ;-).0