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.