Archived

This forum has been archived. Please start a new discussion on GitHub.

Interface Mapping

Hello,

I'm quite new at programming with ICE but I start to getting used to it. After creating some classes, map them as an interface in slice and override them at the server site (this all works well), I've got stuck...

Case:
I have a class: public class TesterClass: ITester with one function: 'Hello'
ITester is the interface for that function:
public interface ITester
{
MyVariable Hello(MyOtherVariable Hey)
}

I want to get this function and it's interface at the server side, so how does the slice code looks like and what do I have to do in the server to get this working...?

I work with Ice 3.4.1, my compiler is Visual Studio 2010 and my OS is Windows 7

Kind Regards

Comments

  • bernard
    bernard Jupiter, FL
    Hello Jens,

    Welcome to our forums!

    With Ice, you should start with Slice definitions, and not with C++ or C# code that you then 'map' to Slice definitions. Many C++/C# etc types have no equivalent in Slice, whereas all Slice definitions can be translated to C++/C#/Java etc. constructs.

    With your example, the issue how to represent the MyVariable and MyOtherVariable types in Slice, and you didn't provide much info :).

    If these types are serializable C# types, and you don't care about language interoperability, you could tell Ice to marshal/unmarshal them as sequences of bytes:
    // Slice
    // See http://www.zeroc.com/doc/Ice-3.4.1-IceTouch/manual/Slice.5.18.html
    
    ["clr:serializable:SomeNamespace.MyVariable"]
    sequence<byte> MyVariable;
    
    ["clr:serializable:SomeNamespace.MyOtherVariable"]
    sequence<byte> MyOtherVariable;
    
    interface ITester
    {
       MyVariable Hello(MyOtherVariable Hey);
    };
    
    

    Best regards,
    Bernard
  • Hello

    Well, I can define my own object types in Slice, that's not the problem and that's not really what I'm trying to ask...
    The problem is that, when I have a Class, it's mapped in Slice by 'Interface' but I don't now how to map a .Net Interface in Slice... Is this also mapped bij 'Interface'?

    And at the server side, how do I override the interface, since it isn't a class but an interface which defines a function from within a class... I know it's explained kind weird, but I don't really know how to explain it in a better way...

    Kind regards

    EDIT: Maybe I used the word 'mapping' in the wrong way, I just mean that I don't know how define a .net interface in slice...
  • bernard
    bernard Jupiter, FL
    Hi Jens,

    You can't define a C# or C++ or Java (etc.) class or interface in Slice. The Slice mapping is only in one direction: Slice to your favorite programming language.

    Conceptually, the Slice construct that corresponds to a C# interface is a Slice interface, so you probably want to create a Slice interface. It's however very unlikely it will translate directly into an existing C# interface.

    For C# and Java, you can pass serializable objects "as is" through Ice operations: on the wire, they appear as sequences of bytes, and the generated code takes care of serializing/unserializing the objects into these sequences of bytes.

    Hope this is clearer now.

    Bernard
  • No, I think I explained it in the wrong way. Let me state it like it is:
    I have two files:

    Itester.cs

    namespace space1
    {
    public interface ITester
    {
    MyVariable Change(MyOtherVariableOne Hello, MyOtherVariableTwo Bye);
    }
    }

    ITesterFunction.cs
    {
    public class ItesterFunction : ITester
    {
    public MyVariable Change(MyOtherVariableOne Hello, MyOtherVariableTwo Bye)
    {
    //This is not the right function, it's just an example
    Console.WriteLine(Hello.ToString() + Bye.ToString());
    }
    }
    }

    That's the current situation, I just have one project with different files (thus classes)... In a third file, I call another function, for example, Printer(string one, string two, ITester Test)

    I now want to change that situation so that the Printer function is brought to the server side.
    Can you give me a complete solution to this problem?

    Kind Regards
  • bernard
    bernard Jupiter, FL
    Hi Jens,

    I think you're misunderstanding how the development process with Ice works: the starting point is and should be Slice definitions, not your C# code. You can't annotate or automatically map / transform some existing C# code to make it distributed with Ice.

    If you provide a short sample of C# code, with fully defined types (no MyVariable etc), we may be able to show you Slice definitions from which slice2cpp generate _similar_ code (or not, it very much depends on the C# types you use). This would nevertheless remain the wrong way to think about your Ice-based application--please start with the Slice definitions.

    Best regards,
    Bernard