Jan R wrote:

    Can't you do the following?

    ServiceHost selfHost = new ServiceHost(typeof(ICalculator),
    baseAddress);


    Michael


 No!

The class given as parameter to typeof(..) have to implement the interface. The interface is the service contract, which the server implements.

I have worked around the problem with a stub, that loads and runs the python script, see attachment. For each stubbed method it calls the python implemented method:

It would be smart to get rid of the stub.

You could at least define the stub in C# with empty implementations - and then have your Python class subclass that directly rather than from the interface. You could then cast pyClass to the concrete type rather than the interface.

A *bit* less work and cleaner. The joy of statically typed languages. :-)

Michael


Regards
Jan Rouvillain

C# stub:

  public class CalculatorServiceStub : ICalculator
  {
    private ICalculator pyCalc;
    public CalculatorServiceStub()
    {
      if (Program.pyr != null)
      {
        Program.pyr.loadscript(@"..\..\..\Calculator\Calculator.py");
        Program.pyr.run();
        pyCalc = (ICalculator)Program.pyr.getInstance("PyCalculator");
      }
    }
    public double Add(double n1, double n2)
    {
      return pyCalc.Add(n1,n2);
    }
    public double Subtract(double n1, double n2)
    {
      return pyCalc.Subtract(n1, n2);
    }
    public double Multiply(double n1, double n2)
    {
      return pyCalc.Multiply(n1, n2);
    }
    public double Divide(double n1, double n2)
    {
      return pyCalc.Divide(n1, n2);
    }
 }

The class PythonRunner is an adapter for loading, compiling, excuting, instantiating objects and exchanging variables in and out of the script Calculator.py.


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to