简体   繁体   English

来自另一个项目的ASP.NET调用方法

[英]ASP.NET calling methods from another project

I am developing a system comsisting of two ASP.NET projects. 我正在开发一个由两个ASP.NET项目组成的系统。 The first project is only accessible from a local IP and holds all the methods and has access to the database. 第一个项目只能从本地IP访问,并拥有所有方法,并且可以访问数据库。 The second project only consists of a userinterface and should get the needed data, by calling methods in the first project, which returns the needed data. 第二个项目仅包含一个用户界面,并且应该通过调用第一个项目中的方法来获取所需的数据,该方法将返回所需的数据。 The second project, is available from any IP. 第二个项目,可以从任何IP获得。

My question is, how can I connect these two projects, so that the second project can access methods in an object, in the first project, using ASP.NET? 我的问题是,如何连接这两个项目,以便第二个项目可以使用ASP.NET访问第一个项目中的对象中的方法?

I have tried with JQuery and AJAX, but with those, I can only access static methods. 我已经尝试过使用JQuery和AJAX,但是使用这些方法,我只能访问静态方法。

You should convert your first project to a Web API Project which has endpoints exposed to clients to do different things over HTTP protocol. 您应该将第一个项目转换为Web API项目,该项目的端点暴露给客户端,以便通过HTTP协议执行不同的操作。 You will call these end points from your second project. 您将从第二个项目中调用这些终点。

Your first project will act like a web service which does all the business logic and database things. 您的第一个项目将像一个Web服务一样执行所有业务逻辑和数据库事务。 Your second project will be thin UI client, which will communicate to the first as needed for getting data,updating data etc. 您的第二个项目将是瘦UI客户端,它将根据需要与第一个进行通信以获取数据,更新数据等。

You can use HttpWebClient class in your first project to communicate to the end points of your Web API project. 您可以在第一个项目中使用HttpWebClient类与Web API项目的端点进行通信。

You can use a "Generic Handler" (a .ashx file). 您可以使用“通用处理程序”(.ashx文件)。 With this you can expose a HTTP endpoints. 这样,您可以公开HTTP端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM