468,168 Members | 1,515 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

Interfaces in a separate assembly...remoting

Hello, I'm hoping someone might be able to help me out. I'm creating a
shared assembly with my interface definitions similar to the following.
When I try to compile the RemotingInterface, everything works. When I
go to compile the RemotingServer assembly, I receive the following
error message. I've included all my references, so I'm almost positive
that's not the issue. Shouldn't this be possible without having to
implement HelloMessage in the RemotingInterface assembly?

Error 2 'RemotingServer.SampleService' does not implement interface
member
'RemotingInterface.ISampleService.HelloWorld(Remot ingInterface.IHelloMessage)'

namespace RemotingInterface
{
public interface IHelloMessage
{
string Message
{
get;
set;
}
}
public interface ISampleService
{
//If I have HelloMessage defined in the same assembly, I change
//IHelloMessage to HelloMessage and
everything works fine.
IHelloMessage HelloWorld(IHelloMessage
message);
}
}

Now, in my server assembly, I have the following:
namespace RemotingServer
{
public class SampleService : MarshalByRefObject, ISampleService
{
//This method declaration throws:
//'ISampleService.HelloWorld' in
explicit interface declaration is not a member of interface
//Shouldn't RemotingServer.HelloMessage
is RemotingInterface.IHelloMessage return true?
HelloMessage
ISampleService.HelloWorld(HelloMessage message)
{
HelloMessage response = new HelloMessage();

return response;
}
}

public class HelloMessage : IHelloMessage
{
public string Message
{
get
{
return "Hello";
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
}
}

Nov 22 '06 #1
5 2439
HelloMessage ISampleService.HelloWorld(HelloMessage message) {
HelloMessage response = new HelloMessage();
return response;
}

Shouldn't that be IHelloMessage at the start? Otherwise it (as stated)
doesn't meet the interface definition. It doesn't matter that HelloMessage :
IHelloMessage; the signature must match.

Marc
Nov 22 '06 #2
Yeah, IHelloMessage works. So if I have properties that return
interface types, I have to go through the exercise of casting each one
to its specific type, i.e.

public interface SomeInterface
{
IAnotherInterface SomeProperty
{
get;set;
}
}

And then in my implementation, I would do something like:

SpecificImplementation _var =
(SpecificImplementation)IAnotherInterface.SomeProp erty
Is this correct? Thanks for the help, I appreciate it.

Nov 22 '06 #3
Well, only if you care about the bits in the specific implementation ;-p
Most of what you need may be (or perhaps /should be/) available in
IAnotherInterface. After all, if you are binding to a specific
implementation, why bother with an interface at all?

In /some/ circumstances, a generic interface may be appropriate... so you
could have

public interface ISomeInterface<Twhere T : IAnotherInterface {
T SomeProperty {get; set;}
}

However, this is again blurring the abstraction that interfaces are meant to
provide, so treat with caution. However, if you know that something
implements IAnotherInterface<SomeImplementation>, then you can call
SomeImplementation result = i.SomeProperty;

Marc
Nov 22 '06 #4
Marc,
Thanks for your help. I completely forgot that I could do

SomeImplementation result = i.SomeProperty;

The reason for defining the interfaces to begin with, was to be able to
use the shared assembly in remoting...which I understood was the method
to use.

Thanks again...

Nov 22 '06 #5
You don't "Have to" use Interfaces for Remoting, as long as both client and
server have a reference to the same assembly (so they know "what" to remote).
However, using an Interface does make things more extensible.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Junoti" wrote:
Marc,
Thanks for your help. I completely forgot that I could do

SomeImplementation result = i.SomeProperty;

The reason for defining the interfaces to begin with, was to be able to
use the shared assembly in remoting...which I understood was the method
to use.

Thanks again...

Nov 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Richard Bell | last post: by
1 post views Thread by Sergei Shelukhin | last post: by
reply views Thread by hoots | last post: by
1 post views Thread by Padu | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.