最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Can I interact with .NET libraries through Javascript? - Stack Overflow

programmeradmin0浏览0评论

We've built a set of .NET libraries (in C#) which are used to interact with an outside resource. The outside resource provide bindings in Java and .NET, so it was necessary to build our libraries in one of those languages and we're officially a Windows shop.

We also use PHP/Javascript for a lot of our front-end web applications. Is it possible for these PHP/Javascript web applications to interact with our .NET libraries? We have both IIS and Apache web servers if that makes a difference. Communication would need to go in both directions.

We've built a set of .NET libraries (in C#) which are used to interact with an outside resource. The outside resource provide bindings in Java and .NET, so it was necessary to build our libraries in one of those languages and we're officially a Windows shop.

We also use PHP/Javascript for a lot of our front-end web applications. Is it possible for these PHP/Javascript web applications to interact with our .NET libraries? We have both IIS and Apache web servers if that makes a difference. Communication would need to go in both directions.

Share Improve this question asked Nov 16, 2009 at 0:27 Josh SmeatonJosh Smeaton 48.8k24 gold badges136 silver badges165 bronze badges 2
  • If you are talking about javascript running in a web browser, then you just described every single AJAX app written in .NET. If you're talking about calling .NET assemblies from JS which is being run on a server via the Windows Scripting Host, then please let us know. – Josh Pearce Commented Nov 16, 2009 at 0:31
  • The question was 'HOW' javascript can 'talk' to C# dlls. I was hoping that there would be a way without using web services. Though I suppose we can write web methods to expose the same functionality and run them on each server that runs an application using them to minimise delay. – Josh Smeaton Commented Nov 16, 2009 at 4:04
Add a ment  | 

3 Answers 3

Reset to default 6

The most obvious approach is exposing your .NET libraries as web services on a web server (either IIS or Apache/Mono). This allows both JS and PHP to consume the same service endpoints (JS via AJAX, PHP vs web service calls).

If extreme performance is a concern - for example, your PHP apps need to make heavy calls into the .NET libraries as if they are native, then web services are probably not the best approach. For that, you might want to look into making COM Callable Wrappers for your .NET libraries and consuming them from PHP.

Although Ajax is the usual approach, another idea for you, in case it might help, would be to use Silverlight on the client side. That way, you would embed your .NET classes into a Silverlight application, which would then be downloaded to the client where it would run inside the browser. Silverlight apps can easily interact bi-directionaly with JavaScript, as well as with remote resources.

For example, you can mark a .NET method with the [ScriptableMember] attribute, which will expose it to JavaScript.

You can pass data via AJAX calls where you municate to and from the client via JSON. For client side data set manipulation jLinq is a great library for performing Linq queries on JSON objects.

If you are looking for a good place to start with web services, JSON and ASP.Net webforms Dave Ward's posts on Encosia are really top notch.

发布评论

评论列表(0)

  1. 暂无评论