Pulling data from web via REST BPM

Hey @steveh

Were you able to get your code to work?

I’m having the same issue with Microsoft.CSharp.RuntimeBinder.Binder and I was wondering if you got your solution working after manually bringing in Microsoft.Csharp dll?

Thanks!

Yes it works now.

I zipped up the dll and put it in the custom folder on the server and added the appropriate line to the config to deploy it

1 Like

I am tying to call a Function from Custom Code and followed the Help documentation, but I cannot get it to work. The code compiles in the Code Editor. I know the Function is working because I can call it from a Data Directive.

This is the error:
Exception caught in: Epicor.Ice.Lib.RestClient

Error Detail

Description: Cannot perform runtime binding on a null reference

This is the Code:

		string restApiKey   = "";
	    string libraryName  = "PartWebService";
	    string functionName = "PartSearch";
		string part = ""; 		

		var functionInputParameters = new RestContent(
	    new
	    {
	        part= "xyz"
	    });
		MessageBox.Show(this.txtUBIC.Text);
		var getByIdParameters = new RestContent(new{ part = part});

		var restClient = new RestClientBuilder()
    		.SetDefaultApiKey(restApiKey)
    		.UseSession(oTrans.CoreSession)
    		.Build();

		var response = restClient.Function.Post(libraryName, functionName, getByIdParameters, published: true);    
		dynamic responseJson = response.GetJsonResult();
		if (responseJson != null)
		{
			MessageBox.Show("JSON response.");
			var functionResult = response.GetJsonResult();
    		DataSet resultDS = Newtonsoft.Json.JsonConvert.DeserializeObject<DataSet>(responseJson["result?"].ToString());
			//DataSet resultDS = JObject.Parse(json)["result?"].ToObject<DataSet>();
			eugUBICResult = (EpiUltraGrid)csm.GetNativeControlReference("ed79ae21-fe97-4624-b030-2224b4123cea");
			eugUBICResult.DataSource = resultDS;
			eugUBICResult.DataBind();
		}
		else
		{
			MessageBox.Show("JSON returned error.");
		}

I have built the rest connection a little differently because we are using SSO but here is what I have done.

Presumably you are passing an API Key and not passing it in blank as per your code snippet?

var restClient = new RestClientBuilder().SetAppServerUrl(this.oTrans.CoreSession.AppServer).SetCompanyId(this.oTrans.CoreSession.CompanyID).SetDefaultApiKey(ApiKey).SetIsSingleSignOn(true).Build();

I took that code snippet verbatim from the Epicor Help – Calling Functions from Custom Code. I do an Epicor Application Event Log and it is triggering the Function, but something else is wrong. Whether I specify a blank API Key or this one in API Key Maintenance. I still get the error.

Server Side Exception

Cannot perform runtime binding on a null reference

Exception caught in: Epicor.Ice.Lib.RestClient

Error Detail

Description: Cannot perform runtime binding on a null reference

Correlation ID: 1a93f4e2-6b3e-4cf9-9c31-0ad0b7f57c92

Client Stack Trace

at Ice.Lib.RestClient.ResilientCaller.d__10.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Ice.Lib.RestClient.ResilientCaller.d__6.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Ice.Lib.RestClient.AsyncToSyncHelper.DoSynchronous[TResult](Task1 task) at Ice.Lib.RestClient.RestClient.Ice.Lib.RestClient.IRestFunctionCaller.Post(String library, String function, RestContent content, Boolean published, IEnumerable1 headers)
at Script.btnGetUBICData_Click(Object sender, EventArgs args)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButtonBase.OnClick(EventArgs e)
at Ice.Lib.Framework.EpiButton.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseEventArgs e)
at Ice.Lib.Framework.EpiButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)