[IronPython] How do I connect to a WCF service...

Matt Tomblin matt_tomblin at hotmail.com
Tue May 6 18:19:47 CEST 2008

I have a WCF service that I wrote in C#.  This is hosted as a windows service and I can happily connect to it from
a C# client by adding a service reference to the aforementioned service within the (using VS 2008) client project.

I would like to connect to the same serivce via IronPython if possible.

If I execute an IronPython script on the local machine where the service exists I am able to
use "clr" etc in to add a reference to the *.dll and utilize the service in that manner without issue.

import clrclr.AddReferenceToFileAndPath("<somePath>\serviceName.dll")import serviceNameLibclient = serviceNameLib.service()client.doSomethingFromService()
However, my goal is to connect to the service that is running like I am doing in the C# client example (using the service reference add
functionality) and not directly to the assembly.  I guess the issue is related to the fact that the service reference add invokes the svcutil
which generates all that lovely code for the C# app in order for me to simply connect the C# client to the service.

I have been experimenting in IronPython but my lack of knowledge in both Python and WCF in general has stumped me and I don't seem
to be able to find anything online that has an example of an IronPython client in this regard.

My expermintation has been along the lines of:
import clr
import System
import System.ServiceModel
import serviceNameLib

uri = System.Uri("http://<address>:8080/serviceName")
binding = System.ServiceModel.WSHttpBinding()
host = System.ServiceModel.ServiceHost(type(serviceNameLib.service))

host.AddServiceEndpoint(serviceNameLib.Iservice, binding, uri)

The contract name 'serviceNameLib.Iservice' could not be found in the list of contracts implemented by the service 'IronPython.Runtime.Types.ReflectedType'.

The final line (in red) is the error I get.  Obviously I am missing something large or perhaps it simply isn't possible the way I am trying to do it.  If anyone can put me out of my coding misery it would be appreciated.



All new Live Search at Live.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080506/c1b3d233/attachment.html>

More information about the Ironpython-users mailing list