Jan R wrote:
Hello IronPython Experts.


How to do the typeof( ) call on an IronPython implemented class in C#?

The need to do a typeof(..) comes from implementing services in Windows Communication Foundation (WCF) in IronPython. The WCF get-statrted sample uses the overloaded constructor of the ServiceHost class that takes a System.Type:

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

I want to replace the CalculatorService with a IronPython class PyCalculator. Note the typeof(...).

I have tried the following without success, in order to give an instance of the IronPython class to the ServiceHost constructor :

ICalculator pyCalc = (ICalculator)pyr.getInstance("PyCalculator");
ServiceHost selfHost = new ServiceHost( (object) pyCalc, baseAddress);

Can't you do the following?

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


Michael

The IronPython class is attached below. The code results in an exception, because the attribute InstanceContextMode have to be set to InstanceContextMode.Single.

The WCF get-started sample is here: http://msdn.microsoft.com/da-dk/library/ms734712(en-us).aspx <http://msdn.microsoft.com/da-dk/library/ms734712%28en-us%29.aspx>

Can anyone help me out?


Regards
Jan Rouvillain

IronPython code:

import clr
clr.AddReference('CalculatorServer')
from Microsoft.ServiceModel.Samples import ICalculator

class PyCalculator(ICalculator):
  "Implements calculator services"

  def Add(self, a, b):
    print 'a ' + a + ' +  b ' + b
    return a+b

  def Subtract(self, a, b):
    print 'a ' + a + ' -  b ' + b
    return a-b

  def Multiply(self, a, b):
    print 'a ' + a + ' * b ' + b
    return a*b

  def Divide(self, a, b):
    print 'a ' + a + ' // b ' + b
    return a/b

C# interface declaration:

namespace Microsoft.ServiceModel.Samples
{
  [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples";)]
  public interface ICalculator
  {
    // Step7: Create the method declaration for the contract.
    [OperationContract]
    double Add(double n1, double n2);
    [OperationContract]
    double Subtract(double n1, double n2);
    [OperationContract]
    double Multiply(double n1, double n2);
    [OperationContract]
    double Divide(double n1, double n2);
  }
}

------------------------------------------------------------------------

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


--
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