I guess you&#39;re stuck with implementing a skeleton class in C# that you then monkey patch (don&#39;t know the term for Python) to give the implementation in python<br><br><div class="gmail_quote">2009/2/16 Jan R <span dir="ltr">&lt;<a href="mailto:janrou@gmail.com">janrou@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><font face="Arial" size="2"><span>Hi,</span></font></div>
<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" size="2"><span>I try to implement WCF services&nbsp;with a IronPython script. I try to implement the services for ICalculator in the WCF get started sample tutorial, 
see attachments below and <a title="http://msdn.microsoft.com/da-dk/library/ms751519(en-us).aspx" href="http://msdn.microsoft.com/da-dk/library/ms751519%28en-us%29.aspx" target="_blank"><font title="http://msdn.microsoft.com/da-dk/library/ms751519(en-us).aspx" face="Times New Roman" size="3">http://msdn.microsoft.com/da-dk/library/ms751519(en-us).aspx</font></a>.</span></font></div>


<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" size="2"><span>Unfortunately I get 
the follwing&nbsp;Exception &quot;InvalidOperationException&quot; with the 
message:</span></font></div>
<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial"><font size="2"><span>&quot;</span>In 
order to use one of the ServiceHost constructors that takes a service instance, 
the InstanceContextMode of the service must be set to 
InstanceContextMode.Single.&nbsp; This can be configured via the 
ServiceBehaviorAttribute.&nbsp; Otherwise, please consider using the ServiceHost 
constructors that take a Type argument.<span>&quot;</span></font></font></div>
<div><font face="Arial"><font size="2"><span></span></font></font>&nbsp;</div>
<div>How do I set the appriated&nbsp;<span style="font-family: Arial;">InstanceContextMode of the python class implemeting the services.</span></div><div><br></div><div><font face="Arial" size="2"><span>Please help me 
out!</span></font></div><div><br></div>
<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" size="2"><span>Regards</span></font></div>
<div><font face="Arial" size="2"><span>Jan 
Rouvillain</span></font></div>
<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" size="2"><span>Attachments.</span></font></div>
<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" size="2"><span>Program.cs:</span></font></div>
<div><font face="Arial" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" size="2"><span><span style="font-family: Verdana; font-size: 11px; line-height: 15px;"><pre style="border-top: 1px solid rgb(200, 205, 222); margin: 0px 0px 10px; overflow: hidden; background-color: rgb(221, 221, 221); padding-left: 5px; padding-right: 5px; display: block; font-family: Verdana,Arial,Helvetica,sans-serif; white-space: pre-wrap; color: rgb(0, 0, 102); font-size: 105%; padding-top: 5px;">
<font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Collections.Generic;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Linq;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Text;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.ServiceModel;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.ServiceModel.Description;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> IronPython;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> IronPython.Hosting;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> Microsoft.Scripting;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> Microsoft.Scripting.Hosting;</font></font></p>

<font size="2"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">namespace</font></font><font size="2"><font color="#000000"> Microsoft.ServiceModel.Samples</font></font></p>

<font size="2"><p>{</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">class</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Program</font></font></p>

<font color="#2b91af" size="2"><font color="#2b91af" size="2"></font></font><font size="2"><p>{</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">static</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> Main(</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2">[] args)</font></p>

<font size="2"><p>{</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Uri</font></font><font size="2"> baseAddress = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Uri</font></font><font size="2">(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;<a href="http://localhost:8000/ServiceModelSamples/Service" target="_blank">http://localhost:8000/ServiceModelSamples/Service</a>&quot;</font></font><font size="2">);</font></p>

<font size="2"></font><p><font color="#008000" size="2"><font color="#008000" size="2">// Se up python implmentation</font></font></p><font color="#008000" size="2"><font color="#008000" size="2"></font></font><font size="2"></font><p>

<font color="#2b91af" size="2"><font color="#2b91af" size="2">PythonRunner</font></font><font size="2"> pyr = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">PythonRunner</font></font><font size="2">();</font></p>

<font size="2"></font><p><font size="2">pyr.loadscript(</font><font color="#a31515" size="2"><font color="#a31515" size="2">@&quot;..\..\..\Calculator\Calculator.py&quot;</font></font><font size="2">);</font></p><font size="2"><p>

pyr.run();</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">ICalculator</font></font><font size="2"> pyCalc = (</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ICalculator</font></font><font size="2">)pyr.getInstance(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;PyCalculator&quot;</font></font><font size="2">);</font></p>

<font size="2"></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">ServiceHost</font></font><font size="2"> selfHost = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ServiceHost</font></font><font size="2">( (</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2">) pyCalc, baseAddress);</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">try</font></font></p><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><font size="2"><p>{</p></font><p><font color="#008000" size="2"><font color="#008000" size="2">// Step 3 of the hosting procedure: Add a service endpoint.</font></font></p>

<font color="#008000" size="2"><font color="#008000" size="2"></font></font><font size="2"><p>selfHost.AddServiceEndpoint(</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">typeof</font></font><font size="2">(</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ICalculator</font></font><font size="2">),</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">WSHttpBinding</font></font><font size="2">(),</font></p>

<font size="2"></font><p><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;CalculatorService&quot;</font></font><font size="2">);</font></p><font size="2"></font><p><font color="#008000" size="2"><font color="#008000" size="2">// Step 4 of the hosting procedure: Enable metadata exchange.</font></font></p>

<font color="#008000" size="2"><font color="#008000" size="2"></font></font><font size="2"></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">ServiceMetadataBehavior</font></font><font size="2"> smb = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ServiceMetadataBehavior</font></font><font size="2">();</font></p>

<font size="2"></font><p><font size="2">smb.HttpGetEnabled = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">true</font></font><font size="2">;</font></p><font size="2"><p>selfHost.Description.Behaviors.Add(smb);</p>

</font><p><font color="#008000" size="2"><font color="#008000" size="2">// Step 5 of the hosting procedure: Start (and then stop) the service.</font></font></p><font color="#008000" size="2"><font color="#008000" size="2"></font></font><font size="2"><p>

selfHost.Open();</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Console</font></font><font size="2">.WriteLine(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;The service is ready.&quot;</font></font><font size="2">);</font></p>

<font size="2"></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Console</font></font><font size="2">.WriteLine(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;Press &lt;ENTER&gt; to terminate service.&quot;</font></font><font size="2">);</font></p>

<font size="2"></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Console</font></font><font size="2">.WriteLine();</font></p><font size="2"></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Console</font></font><font size="2">.ReadLine();</font></p>

<font size="2"></font><p><font color="#008000" size="2"><font color="#008000" size="2">// Close the ServiceHostBase to shutdown the service.</font></font></p><font color="#008000" size="2"><font color="#008000" size="2"></font></font><font size="2"><p>

selfHost.Close();</p><p>}</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">catch</font></font><font size="2"> (</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">CommunicationException</font></font><font size="2"> ce)</font></p>

<font size="2"><p>{</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Console</font></font><font size="2">.WriteLine(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;An exception occurred: {0}&quot;</font></font><font size="2">, ce.Message);</font></p>

<font size="2"><p>selfHost.Abort();</p><p>}</p><p>}</p><p>}</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">class</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">PythonRunner</font></font></p>

<font color="#2b91af" size="2"><font color="#2b91af" size="2"></font></font><font size="2"><p>{</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Dictionary</font></font><font size="2">&lt;</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">String</font></font><font size="2">, </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Object</font></font><font size="2">&gt; options;</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">private</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ScriptEngine</font></font><font size="2"> engine;</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">private</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ScriptScope</font></font><font size="2"> scope;</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">private</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">CompiledCode</font></font><font size="2"> code;</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> PythonRunner()</font></p><font size="2"><p>{</p><p>InitializePythonEngine();</p><p>}</p></font><p>

<font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> InitializePythonEngine()</font></p>

<font size="2"><p>{</p></font><p><font size="2">options = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Dictionary</font></font><font size="2">&lt;</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2">, </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2">&gt;();</font></p>

<font size="2"></font><p><font size="2">options[</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;DivisionOptions&quot;</font></font><font size="2">] = </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">PythonDivisionOptions</font></font><font size="2">.New;</font></p>

<font size="2"></font><p><font size="2">engine = </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Python</font></font><font size="2">.CreateEngine(options);</font></p><font size="2"><p>}</p></font><p>
<font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> loadscript(</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2"> scriptPath)</font></p>

<font size="2"><p>{</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">ScriptSource</font></font><font size="2"> script = engine.CreateScriptSourceFromFile(scriptPath);</font></p><font size="2"><p>

code = script.Compile();</p><p>scope = engine.CreateScope();</p><p>}</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> SetVariable(</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2"> name, </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2"> value)</font></p>

<font size="2"><p>{</p><p>scope.SetVariable( name, value);</p><p>}</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> run()</font></p>

<font size="2"><p>{</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">try</font></font></p><font color="#0000ff" size="2"><font color="#0000ff" size="2"></font></font><font size="2"><p>{</p><p>code.Execute(scope);</p>

<p>}</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">catch</font></font><font size="2"> (</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Exception</font></font><font size="2"> exc) </font></p>

<font size="2"><p>{</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Console</font></font><font size="2">.WriteLine(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;Python exception: &quot;</font></font><font size="2"> + exc.ToString());</font></p>

<font size="2"><p>}</p><p>}</p></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Object</font></font><font size="2"> getInstance(</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2"> className)</font></p>

<font size="2"><p>{</p></font><p><font color="#2b91af" size="2"><font color="#2b91af" size="2">ObjectOperations</font></font><font size="2"> ops = engine.Operations;</font></p><font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2"> obj = scope.GetVariable(className);</font></p>

<font size="2"></font><p><font color="#0000ff" size="2"><font color="#0000ff" size="2">return</font></font><font size="2"> (</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Object</font></font><font size="2">) ops.Call(obj);</font></p>

<p><font size="2">}</font></p><p><font size="2">}</font></p><p><font size="2">}</font></p><p><font size="2"></font>&nbsp;</p><p><font size="2"></font>&nbsp;</p><p><font color="#000000" face="Arial" size="2"><span></span></font>&nbsp;</p>

<p><font color="#000000" face="Arial" size="2"><span>CalaculatorService.cs:</span></font></p><p><font color="#000000" face="Arial" size="2"><span></span></font>&nbsp;</p><font color="#000000"><span><font color="#0000ff"><font color="#0000ff"></font></font><p>

<font color="#0000ff"><font color="#0000ff"><font face="Arial" size="2">using</font></font></font><font face="Arial" size="2"> System;</font></p><font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font face="Arial" size="2">using</font></font></font><font face="Arial" size="2"> System.Collections.Generic;</font></p>

<font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font face="Arial" size="2">using</font></font></font><font face="Arial" size="2"> System.Linq;</font></p><font color="#0000ff"><font color="#0000ff"></font></font><p>

<font color="#0000ff"><font color="#0000ff"><font face="Arial" size="2">using</font></font></font><font face="Arial" size="2"> System.Text;</font></p><font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font face="Arial" size="2">using</font></font></font><font face="Arial" size="2"> System.ServiceModel;</font></p>

<font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font face="Arial" size="2">namespace</font></font></font><font face="Arial" size="2"> Microsoft.ServiceModel.Samples</font></p>

<p><font face="Arial" size="2">{</font></p><p><font size="2"><font face="Arial">[</font><font face="Arial"><font color="#2b91af"><font color="#2b91af">ServiceContract</font></font>(Namespace = <font color="#a31515"><font color="#a31515">&quot;<a href="http://Microsoft.ServiceModel.Samples" target="_blank">http://Microsoft.ServiceModel.Samples</a>&quot;</font></font></font><font face="Arial">)]</font></font></p>

<p><font face="Arial"><font size="2"><font color="#0000ff"><font color="#0000ff">public</font></font> <font color="#0000ff"><font color="#0000ff">interface</font></font> <font color="#2b91af"><font color="#2b91af">ICalculator</font></font></font></font></p>

<font face="Arial"><font size="2"><font color="#2b91af"><font color="#2b91af"></font></font></font></font><p><font face="Arial" size="2">{</font></p><p><font face="Arial"><font color="#008000"><font size="2"><span>&nbsp;&nbsp;&nbsp; </span>// Step7: Create the method declaration for the contract.</font></font></font></p>

<p><font size="2"><font face="Arial"><span>&nbsp;&nbsp;&nbsp; </span>[</font><font color="#2b91af"><font color="#2b91af" face="Arial">OperationContract</font></font><font face="Arial">]</font></font></p><p><font face="Arial"><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span></font></font></font><font face="Arial"><font size="2"><font color="#0000ff">double</font> Add(<font color="#0000ff"><font color="#0000ff">double</font></font> n1, <font color="#0000ff"><font color="#0000ff">double</font></font> n2);</font></font></p>

<p><font face="Arial" size="2"></font>&nbsp;</p><p><font size="2"><font face="Arial"><span>&nbsp;&nbsp;&nbsp; </span>[</font><font color="#2b91af"><font color="#2b91af" face="Arial">OperationContract</font></font><font face="Arial">]</font></font></p>

<p><font face="Arial"><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>double</font> Subtract(<font color="#0000ff"><font color="#0000ff">double</font></font> n1, <font color="#0000ff"><font color="#0000ff">double</font></font> n2);</font></font></p>

<p><font face="Arial" size="2"></font>&nbsp;</p><p><font size="2"><font face="Arial"><span>&nbsp;&nbsp;&nbsp; </span>[</font><font color="#2b91af"><font color="#2b91af" face="Arial">OperationContract</font></font><font face="Arial">]</font></font></p>

<p><font face="Arial"><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>double</font> Multiply(<font color="#0000ff"><font color="#0000ff">double</font></font> n1, <font color="#0000ff"><font color="#0000ff">double</font></font> n2);</font></font></p>

<p><font face="Arial" size="2"></font>&nbsp;</p><p><font size="2"><font face="Arial"><span>&nbsp;&nbsp;&nbsp; </span>[</font><font color="#2b91af"><font color="#2b91af" face="Arial">OperationContract</font></font><font face="Arial">]</font></font></p>

<p><font face="Arial"><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>double</font> Divide(<font color="#0000ff"><font color="#0000ff">double</font></font> n1, <font color="#0000ff"><font color="#0000ff">double</font></font> n2);</font></font></p>

<p><font face="Arial"><font size="2"><span>&nbsp;&nbsp;&nbsp; </span>}</font></font></p><p><font face="Arial" size="2">}</font></p><p><font face="Arial" size="2"></font>&nbsp;</p><p><span><font face="Arial" size="2">Calculator.py</font></span></p>

<p><span><font face="Arial" size="2"></font></span>&nbsp;</p><span><font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font size="2">import</font></font></font><font size="2"> clr</font></p>

<p><font size="2">clr.AddReference(<font color="#800000"><font color="#800000">&#39;PlatformService&#39;</font></font>)</font></p><font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font size="2">from</font></font></font><font size="2"> Microsoft.ServiceModel.Samples <font color="#0000ff"><font color="#0000ff">import</font></font> ICalculator</font></p>

<p><font size="2"></font>&nbsp;</p><font color="#0000ff"><font color="#0000ff"></font></font><p><font color="#0000ff"><font color="#0000ff"><font size="2">class</font></font></font><font size="2"> PyCalculator(ICalculator):</font></p>

<p><font color="#800000"><font size="2"><span>&nbsp;&nbsp;&nbsp; </span>&quot;Implements calculator services&quot;</font></font></p><p><font size="2"><font color="#0000ff"><span></span></font></font>&nbsp;</p>
<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>def</font> Add(self, a, b):</font></p><p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>print</font> <font color="#800000"><font color="#800000">&#39;a &#39;</font></font> + a + <font color="#800000"><font color="#800000">&#39; + b &#39;</font></font> + b</font></p>

<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>return</font> a+b</font></p><p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>def</font> Subtract(self, a, b):</font></p>
<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>print</font> <font color="#800000"><font color="#800000">&#39;a &#39;</font></font> + a + <font color="#800000"><font color="#800000">&#39; - b &#39;</font></font> + b</font></p>

<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>return</font> a-b</font></p><p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>def</font> Multiply(self, a, b):</font></p>
<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>print</font> <font color="#800000"><font color="#800000">&#39;a &#39;</font></font> + a + <font color="#800000"><font color="#800000">&#39; * b &#39;</font></font> + b</font></p>

<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>return</font> a*b</font></p><p><font size="2"></font>&nbsp;</p><p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; </span>def</font> Divide(self, a, b):</font></p>
<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>print</font> <font color="#800000"><font color="#800000">&#39;a &#39;</font></font> + a + <font color="#800000"><font color="#800000">&#39; // b &#39;</font></font> + b</font></p>

<p><font size="2"><font color="#0000ff"><span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </span>return</font> a/b</font></p></span><p><font face="Arial" size="2"></font>&nbsp;</p></span></font><p><font color="#000000" face="Arial" size="2"><span></span></font>&nbsp;</p>

</pre></span></span></font></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>