Creating a dataservice to communicate between c# api and frontend (angular)

我只是一个虾纸丫 提交于 2021-02-11 09:02:03

问题


I need some help with this.

I'm supposed to create a plugin for a webpage in angular that communicates with an API written in C# which is already in a .dll. What is the best approach to this?

I already created a data.service.ts with the following code to get data from the api:

import { Injectable, ValueProvider } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class DataService {
  edge : any = require('edge');

  constructor() { }

  getData(type: String, method: String) {
    var data = this.edge.func({
      assemblyFile: 'C:\Program Files\Common Files\Siemens\Automation\Simatic OAM\bin\CC.CommonInterfaces.dll',
      typeName: 'CC.CommonInterfaces.${type}',
      methodName: '${method}'
    });

    return data(null, function(error, result) {
      if (error) throw error;
      console.log(result);
      return result;
    });
  }

}

I want to use the getData method to get the right data frontend with a button click, while also leaving the code as dynamic as possible.

Any advice on this?

来源:https://stackoverflow.com/questions/59664295/creating-a-dataservice-to-communicate-between-c-sharp-api-and-frontend-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!