How can we integrate our C# code in Drupal CMS - c#

We have C# code, which is backend for us. Now we need it to be used in our website which is developed in Drupal.

As far as I know, there is no easy way to do it. You basically have 2 options:
Rewrite the code in php. It may be not possible to do it however, it depends on what the code does.
Expose c# code as an external webservice (e.g. with WCF) and then consume the webservice. Drupal is able to do it - more info.

A sloppy solution would also be to display your C# page in the Drupal page with an iframe. I do also agree with empi's answer to rewrite the code in php or a web service depending on your requirement.

You can build DLL project (class library) in C# and use the DLL as reference back in the drupal project.
Not sure about this, and never done before.
You better research more.
But, the best way to use the .NET code in another application is to build the required code into DLL project and use in whichever language you want to use.

Related

C# API routines integrated into ASP Classic application?

We have a classic ASP application that isn't going away. We have a new marketing system that we need to access via their API (WDSL). All of their examples are in C#, which I'm trying to learn enough about today to pull this off.
I downloaded Visual Web Developer 2010 Express and have made some progress. Then I realized that I don't know if it's possible to call a C# .net routine from a classic ASP app. I'm a generalist. I know some classic ASP vbscript, some javascript, some AJAX, stuff like that. If it hasn't been necessary at my current job, then I don't know it.
Is it possible to call c# .net files from a classic ASP application? I'd love to know just this, because I'd hate to get it worked out where I can talk to the API, and then find out I can't use what I've written. Everything I've found on StackOverflow has been .net VBScript files off .asp apps. (Heh. And still have to figure out how to deploy what I've done. lol.)
If it's not possible to run C# from .asp pages, then I need to rewrite in VBScript, and I don't know how to convert C# to VBScript. If I can't run c# off .asp, any conversion utilities out there for short routines C#->VBScript? How difficult/stupid is conversion?
(The API url is in the form of https://secure.ourspiffynewmarketingapp.com/API/1.2/Service.svc?wsdl - don't know if that matters, but figured I'd say so, since I've run across some https issues on my searches.)
I've been on StackOverflow off and on for 11 hours, and I still don't know the answers to these questions.
I don't need to get the whole thing figured out tonight, but I do need to confirm that I can access the API, and since all of the examples are in C#, which I've never even LOOKED at before today, I can't even confirm that.
I couldn't find exactly how I implemented it but did find this article that is pretty much the same thing.
classic-asp-soap-request
Re : Is it possible to call c# .net files from a classic ASP application?
In order to access 'dll' (assembly code) you need to map your top level (exposed components) as COM callable wrappers, and register these as COM components. You can then use them in your ASP Classic just as any other COM component Server.CreateObject('MyProgIdGoesHere')
Have a look here if you need to call SOAP web services from ASP Classic, using the Microsoft.XMLHTTP component (from memory there might have been a server version of this as well). You will need to build up the SOAP request and parse the response yourself, however :(
Edit If you are feeling brave, you might also look at starting the conversion process from ASP Classic across to .NET.

java vs C# web service clients

I've been doing java web services for a couple of years here and there and I've always heard about the ease of use of C#.Net Soap-WS clients. I just tried it out and I have to say, I am a bit jealous - having had to fight through generated code with both Axis and CXF (try using Axis in OSGi or with NTLM authentication...or just look at the horrible generated code, or try using dynamic URL's in CXF).
Is there a java analog to the simplicity of .Net (soap) web service clients? Ideally, you would add the URL to your project, just like you add a service reference in Visual Studio and the behind the scenes code would be setup for you. Is this possible? If not, why not - what is C#.Net doing differently?
I've had good luck with the Spring Framework . Its not quite as easy as C#'s toolset, but when you get down to it, its all just reading a WSDL and generating client adapters. Visual studio lets you do that with the push of a button where with Spring, you can use Ant/Maven to generate your proxies/adapters. Most IDE's will do this for you too (see Randolpho's answer, I know IntelliJ Idea does).
Edit: I believe SoapUI will do this as well, although I haven't used it so I can't tell you how well that works
Eclipse will create a Java web service client very similar to a Service Reference.
http://www.eclipse.org/webtools/jst/components/ws/M3/tutorials/WebServiceClient.html

C#: Correct project template for REST API library?

I want to consume a series of REST services from a provider. But there are a lot of functions I can call and send to the server, so I think it would be a good idea to create a separate library that my C#/MVC2 project can reference and call.
In VS2010, what is the correct project I should select to create this new library? Just plain old "Class library?" It's grouped under "Windows" so I don't know if the correct template to use for a web project.
Thanks.
"Class Library" would be fine. The Class library template is not tied to anyone particular type of project, so they can be used for Web, Console, Windows, Wpf etc.
Of course the functionality you provide in the Class library might be limited to a specific execution evironment because of the functionality you might put into the library, for example if you develop a bunch of functions that expect to be run in an ASP.NET environment then the functionality of the class library might not be applicable to a Console application.
Technically, yes, a "Class library" will give you what you want. Consider, however, whether there are any potential benefits for you in creating a proxy Web Service that you use as an intermediary between your own application(s) and the remote provider. Doing so allows additional management options that can be performed separately from the calling application.
You could also try the MSDN REST Starter Kit. It contains VS templates that help you do all the RESTful things you could ever imagine doing.

Is it possible to embeded js into c#

Currently I'm involved in a project using c# . I know some of the features of this project can be easily implemented using Javascript (I have been a js developer for some time, but totally new to c#). so I'm very eager to know if it is possible to reuse the available js code in the project, or put it another way, embeded js into c# .
thanks in advance.
I think you're asking if it is possible to run JavaScript on the CLR. Similar to Java 6's JVM script engine.
EcmaScript.net could be your best bet - http://code.google.com/p/ecmascript-net/ - see also this question - Are there any .NET CLR/DLR implementations of ECMAScript?
There is an extensive article written on how to embed Javascript within C# here. Is that what you are looking for?
Are you referring to ClientScriptManager RegisterClientScriptBlock Method
There is no reason you cant continue to use existing client side javascript code.
There is a still a clear distinction to whats required on the client and what can be called by the client.
Various possibilities include: calling web services, making ajax calls to WebMethods and injecting javascript code into pages.
The way you write it it sounds like a giant cop-out of learning C# properly. Unless you actually mean that you want to use JavaScript for client-side control of your project, this is a no-go (and it doesn’t sounds like you meant client-side scripting).
That said, .NET actually allows you to mix assemblies from different languages effortlessly, but this only applies to .NET languages which can be compiled to .NET IL (bytecode) and I’m not aware of a JS-to-IL-compiler.
Javascript runs in the browser, as long as it is a web project there is no problblem combining. C# code will run on the server, javascript code in the browser.
http://msdn.microsoft.com/en-us/library/aa479011.aspx

How can I get C# to interop with Javascript?

I'd like to host Javascript in my C# program. I would like to allow users to write custom Javascript code, and have my C# program run their functions, as well as allow the users to use my framework code.
Is it possible to do this? If so, how?
Edit: To be clear, I am not using ASP.NET for this project.
you can also use a webbrowser control to host the javascript in a html document, to interact between the two you would make a COM visible class and set an instance of it to the ObjectForScripting property.
Any public members of the 'external' class are now accessible through window.external in javascript. Also, from the managed code side you can use the InvokeScript method of the document to call any javascript functions.
This way it is easy to pass complex objects between the two.
I used this idea quite a bit in this Google Earth Api application.
http://fraserchapman.blogspot.com/2008/08/google-earth-plug-in-and-c.html
I'd highly recommend you use the Microsoft Dynamic Langauage Runtime (DLR). It's purpose in life is to facilitate scripting in a .Net environment. The DLR is not script specific so over time more script languages will be built on top of it but at the moment the ones I know about are IronRuby, IronPython and JScript.
Spidermonkey .NET Is probably what you are looking for.
I'm not sure how developed it is. Buts its basically a port of Mozilla's Spidermonkey Javascript parser engine which I like a lot.
Or you can evaluate it directly
The way to do this used to be the Windows Script Host, which permitted you to host either JSCript or VBScript.
You can certainly run Javascript natively from C# - see this article for a starter. Having the Javascript access your framework could be tricker, though. Perhaps Script# could help?
There are HTML components where you can embed JavaScript. For the other way the proper thing is an ASP.NET web service. Perhaps with a smart client you can combine both.

Categories