system.net.httpPost Help

Hi! I’m new in using Ignition and needs a little help on system.net.httpPost

I’m trying to reuse an existing and working .NET WCF Restful Web Service.
However, when trying to consume the WS using the below python code:

[b]url = ‘http://localhost/testserv/EquipmentService.svc/Create2
param = {“id”:“test11234”}

response = system.net.httpPost(url, param)
system.gui.messageBox(response)[/b]

the parameter string id that i passed unto the webservice becomes null so I will fail inserting the data
to the DB.

this is my C# code for the webservice:

This is the interface:

[OperationContract]
[WebInvoke(Method = “POST”, UriTemplate = “Create2?id={id}”, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
string Create2(string id);

this is the actual service code:

[b]public bool Create2(string id)
{
string connString = ConfigurationManager.ConnectionStrings[“MyConn”].ConnectionString;

        try
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                using (SqlCommand cmd = new SqlCommand("InsertEquipment", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@EquipID", SqlDbType.NVarChar).Value = id;

                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            return true;
        }
        catch(Exception e)
        {
            return false;
        }
    }[/b]

When I tried to determine the value of the parameter string id, it seems that the value being passed is null so the response i will be getting from the Restful API will always be false.

Btw. Some python forum recommends using “requests.post()” however, I cant seem to import the requests module in Ignition.

Any help is greatly appreciated. :smiley:

Nevermind. Found some solutions online. Thanks.

Hi! Welcome to the forums. Sorry to be late for the party. :slight_smile:

Glad you got it sorted out. Just wanted to point out that Ignition uses Jython and not CPython (that’s pyhton based on C). You’ll find that some libraries-- numpy, for example-- won’t work with Jython because it’s heavily C-based. Pure Pyhton code usually works well, but anything requiring a C library will derail.

Just wanted to give you a heads up for future reference!

EDIT: Almost forgot: Jython will let you use Java libraries, so there will be other features available to you.

Regards,