Great glad to see some interest. I am new to EF and this forum so hopefully I don't defy conventions. If anyone has any suggestions or questions about any content, how I am formating things please feel free to ask or correct where I am going wrong.
So this notion came from sitting through EF training. The module where you built an EF system to calculate Fahrenheit from Celsius, pointed out to me that EF scripting could use some help. I am lazy and building all of the objects necessary just to convert those values was bothering me. Simply put EF by itself had an issue with easily calculating (9/5) * x + 32. It took 4 or 5 steps.
So what are the options?
1.Write that into your EF system 5 steps.Ok if you force me to.2. Write a C# dll and expose those methods. This will work, I suspect it is what most everyone is doing in instances like this. I think this is brilliant. However; I was looking for something that I could prototype in faster, and wanted to keep the source files open to modify by anyone. Not just those with Visual Studio (software and understanding), and C# programming skills. Plus who likes compiling and copying DLLs every time you want to test a change? 3 See if someone else built something I can use, (dll or WSDL page?) Not a sure thing. 4. See if I can make a scripting language available to EF? This is what I am exploring.
I like to code in Python (started learning last November) and since it is: Easy to learn, will run on almost any system (Windows, Mac, Linux, ChromeOS, etc...), and is easy to extend. This is where I turned to, I figured this could help out the whole EF community. I hope that there is a thriving one.
I am going to build up to what I have been working on most recently since there are applications that can benefit from the intermediate steps. For this step we will use a prebuilt library in Python for formatting SOAP and use and EF webmethod to get the answer. So if you are interested in building SOAP interfaces for other reasons this may be your lucky day.
First for those without Python knowledge. I will try to make this where you don't need it (or much of it), but I would highly suggest you learn some. You won't regret it.
Let’s look at the python code to have a function that converts Fahrenheit from Celsius.
Fahrenheit = 9.0/5.0 * Celsius + 32
This should be fairly straight forward. I am trying to keep this from being a Python tutorial, so I won’t explain too much here. Takes Celsius and returns Fahrenheit as a float. The inverse function below. Why not be able to convert both ways?
Celsius = (Fahrenheit - 32) * 5.0/9.0
I left the explicit conversion to a float in the return statement off because I was playing around with what will happen when the response makes it back to EF. As you will see later, I haven’t figured out all of the implications but would love to discuss them with you guys.
Alright. I built my system on a VM, running Ubuntu. Though for this tutorial I tested it out and works just fine with Python 3.6 running on Windows 10. This solution is NOT ready for production, but for testing out things and seeing if you want to scale it up you can’t beat how fast you will be up in running. In 5 parts:
First Install Python on something. I would not suggest your EF server, I personally am trying to keep the server clean, which is why I am using web methods and api for this stuff. Plus if you like this you can scale up easy.
Second create a virtual environment in python and install some modules. Useful in our case if stuff goes bad. We can just delete the Python venv and try again.
Third create file with Python code in it.
Fourth test our WSDL service
Last test the WSDL service from EF.
You may be able to skip the first step if you are not running windows, you probably have Python installed already.
https://www.python.org/downloads/ I would suggest you install for all users, add it to the environment (look for check box), and name the directory you install into based on what version of python you are installing. You can run multiple versions side by side and this will make it easier later on if you decide to rev versions. In my case (C:\Python36) is for the 64bit version and (C:\Python36-32) for the 32bit version. Oracle database access is easier to set up on the 32bit version of Python for me.
Open a command prompt.
Make a directory where you are going to keep your source files.
Create a Python virtual environment called wsdltest (name doesn’t matter)
Install the spyne module into that virtual environment using pip. (Pip will automatically download any files it needs) linux/mac users substitute the Scripts directory for bin so: ( python_projects>wsdltest\bin\pip install spyne ) for the first step etc....
The virtual environment bit makes a copy of Python in a directory named after the venv in this case it is wsdltest. Since it is a copy it is easily removed if something happens, and venvs are very useful making sure you have the right versions of libraries in use by your code.
Change all of the “localhosts” in your tempservice.py to the ip address of where your code is running. The important one is the server = make_server(‘localhost’...) line. This will make the simple wsgi server from spyne that python is using answer other hosts.
Now Create an EF system, add a webmethod change the url to point to our WSDL service, click on “Generate Methods”
At this point you should see the methods exposed by our microservice.
Set up some parameters and test it out.
Use a real web server like apache or NGIX. This would be for production. The spyne wsgi server is good for testing would not recommend running in production.
Examing type errors. If you noticed I was returning a float from the python code, EF read it as a single. Because of this I am curious if I can try to pass a double (from EF) to this web method and how it is treated. I suspect that EF has helper DLLs' that are handling the web request. If those dlls are strongly typed, it may the case that there is truncation between EF and its' helper. Spyne supports Decimal, and Double types so this concern may be unique to Floats vs Singles or Doubles. I will need to do some testing to prove this out. It is counter intuitive that a Python float doesn’t match a .Net float. Languages like C#, C++, C, and Java use float(or Single) for single precision numbers. Python is the odd one here, float is any number with a floating point. So really be aware when you create your functions and decorators in Python to account for other systems interpretations of those values. To avoid all of this concern I would suggest using double in your decorators when dealing with any floating point numbers you plan on exposing with in these SOAP interfaces.
Ok thats it for now. Next tutorial will be on building RESTful interfaces for use with EF faster and more modern. SOAP is nice but very heavy in terms of response. Look at the XML to generate the web methods. Also look at the return XML. In this example we are getting scalar data. A single (float/single). SOAP is sending a lot of data back just for this. Hope that this was helpful for someone.