locked
Missing definitions (Versions) RRS feed

  • Question

  • User-1852975005 posted

    Hi,

    Two errors

    Client.RemoteCertificateValidationCallback

    RestClient does not contain definition RemoteCertificateValidationCallback

    -----------------------------------------------------------------------------------

    request.AddJsonBody

    RestRequest does not contain definition AddJsonBody

    -----------------------------------------------------------------------------------

    I had to update the version of RestClient to suit the framework. So I am guessing definition names have changed?

    Thanks,

    Friday, March 27, 2020 2:52 AM

Answers

  • User753101303 posted

    You should find this in a packages.config file. Else see References and check the DLL version. I'm always using the "nuget console" and l https://www.nuget.org/packages/RestSharp to install a package.

    For now it looks like you are using an old version.

     Edit: not directtly related but you should you should investigate what is invalid and possibly fix this. Accepting blindly a non valid certificate is likely not a good idea.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 29, 2020 6:41 AM

All replies

  • User753101303 posted

    Hi,

    Be explicit. For now we have to guess which RestClient package and for which framework version. From a quick check it seems RemoteCertificateValidationCallback is not supported in .NET 4 assuming you are using RestSharp (but I have no idea if this is what you are using)

    It doesn't have a documenta&tion and/or is not open source ?

    Friday, March 27, 2020 1:10 PM
  • User-1852975005 posted

    PatriceSc

    Hi,

    Be explicit. For now we have to guess which RestClient package and for which framework version. From a quick check it seems RemoteCertificateValidationCallback is not supported in .NET 4 assuming you are using RestSharp (but I have no idea if this is what you are using)

    It doesn't have a documenta&tion and/or is not open source ?

    Hi,

    Platform Active (Any CPU)

    I have commented the issues with // Issue on this line

    (I had to use a HTML to text converter, hope I get an answer).

    using Newtonsoft.Json;
    using RestSharp;
    using RestSharp.Authenticators;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Helpers;
    using System.Web.Script.Serialization;
    using System.Windows.Forms;
    
    
    namespace restClient_0
    {
        public partial class Form1 : Form
        {
            static object[] obj;
            restClient_0.WebRefSCX.SCXService MySoap;
    
    
            public Form1()
            {
                InitializeComponent();
                MySoap = new restClient_0.WebRefSCX.SCXService();
                StartSoap();
            }
    
            private void cmdGO_Click(object sender, EventArgs e)
            {
    
                var Client = new RestClient("https://xx.xx.xx.xx:xxxx/rest/system/workService");
    
                Client.RemoteCertificateValidationCallback = (sender1, certificate, chain, sslPolicyErrors) => true;
    
                var request = new RestRequest();
    
                request.Method = Method.POST;
    
                request.AddHeader("authorization", "Basic xxxxxxxxxxxxxxxxxxxx");
    
                string POSTString = "{\r\n      \"action\": \"read\",\r\n      \"header\": {\r\n\t\t\"requestor\": \"WorkOrderCreateService\",\r\n\t\t\"dateTime\": \"DD/MM/YYYY HH:MM:SS\",\r\n\t\t\"messagePriority\": \"1\",\r\n\t\t\"correlationId\": \"\"\r\n\t},\r\n      \"payload\": {\r\n\t     \"workOrder\": {\r\n           \t\"workOrder\": \"xxxxxx3\"\r\n          \r\n\t\t}\r\n      }\r\n}";
    
                request.AddJsonBody(POSTString);
    
                IRestResponse response = Client.Execute(request);
    
                string strJSON = string.Empty;
    
                debugOutput(strJSON);
    
                txtResponse.Text = POSTString;
    
                txtResponce2.Text = response.Content;
    
                var result = JsonConvert.DeserializeObject(response.Content);
    
                string resultString = result.ToString();
    
                txtBox1.Text = resultString;
                //*************************
    
                RootObject Root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(response.Content);
    
                //*************************
    
                string workOderString = Root.payload.workOrder.workDTO.workOrderDesc.ToString();
    
                txtBox2.Text = workOderString;
    
                //*************************
    
                bool successBool = Root.success;
    
                //bool successBool = Root.payload.workOrder.workDTO.calculatedMatFlag; //For Example of false
    
                txtSuccess.Text = successBool.ToString();
    
            }
    
            private void debugOutput(string strDebugText)
            {
                try
                {
                    System.Diagnostics.Debug.Write(strDebugText + Environment.NewLine);
                    txtResponse.Text = txtResponse.Text + strDebugText + Environment.NewLine;
                    txtResponse.SelectionStart = txtResponse.TextLength;
                    txtResponse.ScrollToCaret();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write(ex.Message, ToString() + Environment.NewLine);
                }
            }
    
            public void StartSoap()
            {
                GetValue.Enabled = false;
                SetValue.Enabled = false;
                if (ServerName.Text.Length > 0)
                {
                    // override default connection to server
                    MySoap.Url = "http://localhost/webservices/scx";
                }
                bool limit;
                obj = new object[0];
                object[][] retobj;
                PointList.Items.Clear();
                GetValue.Enabled = false;
                SetValue.Enabled = false;
                try
                {
                    // define SQL query, results are in retobj
                    retobj = MySoap.ExecuteQuery("Select FullName from CDBPoint", obj, out limit);
                    for (int i = 0; i < retobj.Length; i++)
                        PointList.Items.Add(retobj[i][0].ToString());
                }
                catch (Exception exc)
                {
                    ServerName.Text = exc.Message.ToString();
                }
    
            }
    
            private void PointList_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (PointList.SelectedIndex == -1)
                {
                    GetValue.Enabled = false;
                    SetValue.Enabled = false;
                }
                else
                {
                    GetValue.Enabled = true;
                    SetValue.Enabled = true;
                }
    
            }
    
            private void btnSOAP_Click(object sender, EventArgs e)
            {
                Cursor.Current = Cursors.WaitCursor;
                StartSoap();
                Cursor.Current = Cursors.Default;
            }
    
            private void GetValue_Click(object sender, EventArgs e)
            {
                obj = new object[0];
                object[][] retobj;
                bool limit;
                retobj = MySoap.ExecuteQuery("Select CurrentValueFormatted, FullName from CDBPoint where FullName='" + PointList.SelectedItem + "'", obj, out limit);
                PntValue.Text = retobj[0][0].ToString();
            }
    
            private void SetValue_Click(object sender, EventArgs e)
            {
                obj = new object[1];
                object retobj;
                try
                {
                    obj.SetValue(float.Parse(PntValue.Text), 0);
                    retobj = MySoap.ExecuteMethod(PointList.SelectedItem.ToString(), "CurrentValue", obj);
                    ErrMessage.Text = "No Error";
                }
                catch (Exception exc)
                {
                    ErrMessage.Text = exc.Message;
                }
            }
        }
    }
    



    Monday, March 30, 2020 2:09 AM
  • User409696431 posted

    Can you try again without pasting HTML into the post?

    Monday, March 30, 2020 2:31 AM
  • User-1852975005 posted

    Can you try again without pasting HTML into the post?

    I did, I tried a few times.

    Monday, March 30, 2020 2:52 AM
  • User409696431 posted

    How are you posting?  It should be as simple as typing into the form.  Don't copy/paste from a source that is HTML.

    Monday, March 30, 2020 2:59 AM
  • User753101303 posted

    Use the {;} button from the editor bar to insert code snippet.

    And which framework version do you target? I saw that .RemoteCertificateValidationCallback is not supported for .NET 4 (you need 4.5 or later).

    Monday, March 30, 2020 11:58 AM
  • User-1852975005 posted

    PatriceSc

    Use the {;} button from the editor bar to insert code snippet.

    And which framework version do you target? I saw that .RemoteCertificateValidationCallback is not supported for .NET 4 (you need 4.5 or later).

    Framework Version 4.5.2

    using Newtonsoft.Json;
    using RestSharp;
    using RestSharp.Authenticators;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Helpers;
    using System.Web.Script.Serialization;
    using System.Windows.Forms;
    
    
    namespace restClient_0
    {
        public partial class Form1 : Form
        {
            static object[] obj;
            restClient_0.WebRefSCX.SCXService MySoap;
    
    
            public Form1()
            {
                InitializeComponent();
                MySoap = new restClient_0.WebRefSCX.SCXService();
                StartSoap();
            }
    
            private void cmdGO_Click(object sender, EventArgs e)
            {
    
                var Client = new RestClient("https://xx.xx.xx.xx:xxxx/rest/system/workService");
    
                Client.RemoteCertificateValidationCallback = (sender1, certificate, chain, sslPolicyErrors) => true;
    
                var request = new RestRequest();
    
                request.Method = Method.POST;
    
                request.AddHeader("authorization", "Basic xxxxxxxxxxxxxxxxxxxx");
    
                string POSTString = "{\r\n      \"action\": \"read\",\r\n      \"header\": {\r\n\t\t\"requestor\": \"WorkOrderCreateService\",\r\n\t\t\"dateTime\": \"DD/MM/YYYY HH:MM:SS\",\r\n\t\t\"messagePriority\": \"1\",\r\n\t\t\"correlationId\": \"\"\r\n\t},\r\n      \"payload\": {\r\n\t     \"workOrder\": {\r\n           \t\"workOrder\": \"xxxxxx3\"\r\n          \r\n\t\t}\r\n      }\r\n}";
    
                request.AddJsonBody(POSTString);
    
                IRestResponse response = Client.Execute(request);
    
                string strJSON = string.Empty;
    
                debugOutput(strJSON);
    
                txtResponse.Text = POSTString;
    
                txtResponce2.Text = response.Content;
    
                var result = JsonConvert.DeserializeObject(response.Content);
    
                string resultString = result.ToString();
    
                txtBox1.Text = resultString;
                //*************************
    
                RootObject Root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(response.Content);
    
                //*************************
    
                string workOderString = Root.payload.workOrder.workDTO.workOrderDesc.ToString();
    
                txtBox2.Text = workOderString;
    
                //*************************
    
                bool successBool = Root.success;
    
                //bool successBool = Root.payload.workOrder.workDTO.calculatedMatFlag; //For Example of false
    
                txtSuccess.Text = successBool.ToString();
    
            }
    
            private void debugOutput(string strDebugText)
            {
                try
                {
                    System.Diagnostics.Debug.Write(strDebugText + Environment.NewLine);
                    txtResponse.Text = txtResponse.Text + strDebugText + Environment.NewLine;
                    txtResponse.SelectionStart = txtResponse.TextLength;
                    txtResponse.ScrollToCaret();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write(ex.Message, ToString() + Environment.NewLine);
                }
            }
    
            public void StartSoap()
            {
                GetValue.Enabled = false;
                SetValue.Enabled = false;
                if (ServerName.Text.Length > 0)
                {
                    // override default connection to server
                    MySoap.Url = "http://localhost/webservices/scx";
                }
                bool limit;
                obj = new object[0];
                object[][] retobj;
                PointList.Items.Clear();
                GetValue.Enabled = false;
                SetValue.Enabled = false;
                try
                {
                    // define SQL query, results are in retobj
                    retobj = MySoap.ExecuteQuery("Select FullName from CDBPoint", obj, out limit);
                    for (int i = 0; i < retobj.Length; i++)
                        PointList.Items.Add(retobj[i][0].ToString());
                }
                catch (Exception exc)
                {
                    ServerName.Text = exc.Message.ToString();
                }
    
            }
    
            private void PointList_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (PointList.SelectedIndex == -1)
                {
                    GetValue.Enabled = false;
                    SetValue.Enabled = false;
                }
                else
                {
                    GetValue.Enabled = true;
                    SetValue.Enabled = true;
                }
    
            }
    
            private void btnSOAP_Click(object sender, EventArgs e)
            {
                Cursor.Current = Cursors.WaitCursor;
                StartSoap();
                Cursor.Current = Cursors.Default;
            }
    
            private void GetValue_Click(object sender, EventArgs e)
            {
                obj = new object[0];
                object[][] retobj;
                bool limit;
                retobj = MySoap.ExecuteQuery("Select CurrentValueFormatted, FullName from CDBPoint where FullName='" + PointList.SelectedItem + "'", obj, out limit);
                PntValue.Text = retobj[0][0].ToString();
            }
    
            private void SetValue_Click(object sender, EventArgs e)
            {
                obj = new object[1];
                object retobj;
                try
                {
                    obj.SetValue(float.Parse(PntValue.Text), 0);
                    retobj = MySoap.ExecuteMethod(PointList.SelectedItem.ToString(), "CurrentValue", obj);
                    ErrMessage.Text = "No Error";
                }
                catch (Exception exc)
                {
                    ErrMessage.Text = exc.Message;
                }
            }
        }
    }
    Monday, March 30, 2020 10:35 PM
  • User475983607 posted

    The WinForms code instantiates a type named RestClient then tries to invoke a method named AddJsonBody() which is not a member (method) in RestCleint. I assume the upgraded RestClient API deprecated the AddJsonBody() method.  Since Restclient is a 3rd party library, you should read the documentation to figure out how to migrate your code.  

    Keep in mind, this is an ASP.NET forum not WinForms or RestCleint. 

    Tuesday, March 31, 2020 12:00 AM
  • User-1852975005 posted

    The WinForms code instantiates a type named RestClient then tries to invoke a method named AddJsonBody() which is not a member (method) in RestCleint. I assume the upgraded RestClient API deprecated the AddJsonBody() method.  Since Restclient is a 3rd party library, you should read the documentation to figure out how to migrate your code.  

    Keep in mind, this is an ASP.NET forum not WinForms or RestCleint. 

    Sorry that its in the wrong location.

    It is possible for me to combine the two though?

    The WinForms code instantiates a type named RestClient then tries to invoke a method named AddJsonBody() which is not a member (method) in RestCleint. I assume the upgraded RestClient API deprecated the AddJsonBody() method.  Since Restclient is a 3rd party library, you should read the documentation to figure out how to migrate your code.  Where do I find the documentation?

    Thanks,

    Tuesday, March 31, 2020 12:15 AM
  • User-1852975005 posted

    These are the two errors I am getting

    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS1061	'RestClient' does not contain a definition for 'RemoteCertificateValidationCallback' and no accessible extension method 'RemoteCertificateValidationCallback' accepting a first argument of type 'RestClient' could be found (are you missing a using directive or an assembly reference?)	SoapClnt	C:\Users\Administrator\Documents\Soap Client\SoapClnt\SoapClnt\Form1.cs	324	Active
    
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS1061	'RestRequest' does not contain a definition for 'AddJsonBody' and no accessible extension method 'AddJsonBody' accepting a first argument of type 'RestRequest' could be found (are you missing a using directive or an assembly reference?)	SoapClnt	C:\Users\Administrator\Documents\Soap Client\SoapClnt\SoapClnt\Form1.cs	334	Active
    

    I've updated the target framework to 4.6. I can't find any documentation on RestClient.


    Tuesday, March 31, 2020 9:11 PM
  • User-1852975005 posted

    I don't know if this is a fix, but when I remove the json and just have AddBody it removes the error for that?

    Still stuck with the 

    RemoteCertificateValidationCallback
    Tuesday, March 31, 2020 10:12 PM
  • User1535942433 posted

    Hi NewToDotyNet,

    Accroding to your description and codes,as far as I think,the question means your code haven't used the RemoteCertificateValidationCallback Extension method.

    I suggest you could post the original link of codes to us.It will help us to solve your problem.

    Best regards,

    Yijing Sun

    Wednesday, April 1, 2020 8:36 AM
  • User753101303 posted

    Works fine here with the latest RestSharp version (106.10.1).

    Could it be that you now target 4.6 but keep using an old RestSharp package? Try perhaps to update this package for example using https://docs.microsoft.com/en-us/nuget/reference/ps-reference/ps-ref-update-package

    Wednesday, April 1, 2020 1:12 PM
  • User753101303 posted

    Also I see AddJsonBody? In the packages.config file do you have a line such as:

    <package id="RestSharp" version="106.10.1" targetFramework="net452" />

    To me you are likely using an old version done for .NET 4.0 ?

    Wednesday, April 1, 2020 1:19 PM
  • User-1852975005 posted

    Hi,  have done a search on <package id="RestSharp" on the entire project and have found no such text.
    Where should it be?

    The target framework is : .NET Framework 4.6

    Client.RemoteCertificateValidationCallback = (sender1, certificate, chain, sslPolicyErrors) => true;
    Now no longer works, so I cannot give it the certificate.

    RestClient does not contain this definition.
    Is there an equivalent definition please?

    Fortunately I have the original code and I am able to test it successfully.

    Wednesday, April 29, 2020 1:17 AM
  • User-1852975005 posted

    Please tell me what I am about can be done?

    Wednesday, April 29, 2020 1:57 AM
  • User753101303 posted

    You should find this in a packages.config file. Else see References and check the DLL version. I'm always using the "nuget console" and l https://www.nuget.org/packages/RestSharp to install a package.

    For now it looks like you are using an old version.

     Edit: not directtly related but you should you should investigate what is invalid and possibly fix this. Accepting blindly a non valid certificate is likely not a good idea.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 29, 2020 6:41 AM
  • User-1852975005 posted

    Hi,

    thanks so much Patrice, I have been going around in circles.

    (I also had to change  request.AddBody(POSTString); to request.AddJsonBody(POSTString);)

    However, I am back to where I was previously, but better as the two projects are merged.
    I can get back on with completing other requirements for this area.

    Many thanks!

    Wednesday, April 29, 2020 10:16 PM