How to access an API running on a remote machine via network

1.6k views Asked by At

I want to connect to an OKUMA Windows based control from external PC (i.e. Other than OKUMA controller) and utilize the OKUMA Open API on that machine. Is it possible? (If yes then How?)

Below is my code which I want to run from my laptop to check machine running mode. I'm getting errors because Okuma.CLDATAPI can't run on my local PC :

using Okuma.CLDATAPI.Enumerations; // Part of the API on the machine
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OKUMA_TRIAL
{
    public partial class Form1 : Form
    {
        Okuma.CLDATAPI.DataAPI.CMachine objCMachine;
        public Form1()
        {
            InitializeComponent();

            objCMachine = new Okuma.CLDATAPI.DataAPI.CMachine();
            objCMachine.Init();
        }

        private ExecutionModeEnum fnGetRunMode()
        {
            return objCMachine.GetExecutionMode();
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            txtRunMode.Text = fnGetRunMode().ToString();
        }
    }
}

If this isn't possible, is there another way to communicate with the machine?

1

There are 1 answers

0
Scott Solmer On

Use Windows Communication Foundation to wrap the API.

Due to popular demand, the Open API SDK now includes a WCF client / service example.

WCF Example Service and Client

It is important to note that we do not feel comfortable releasing code of a publicly available service with API access, so this example is configured for local-host only. Of course it is trivial to change the configuration, but whomever does so needs to accept all responsibility for doing so.

Microsoft has actually done a good job of documenting WCF features, see below.


Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4