0

i have a class library in c# and i added that dll as a reference to the web site and I want to access the methods which are in the class library. when I tried accessing those methods using ActiveXobject it throwing an exception saying object cant be created

namespace Office
{
    public class Algebra
    {
        public double Addition(double x, double y)
        {
            return x + y;
        }
    }
}

this is my method in c# class library. and my javascript is as follows

(function () {
        alert("suresh");
        var myobj;
        myobj = new ActiveXObject("Office.Algebra");
        alert(myobj);
        var add = myobj.Addition(7, 6);
        alert(add);
    })();

2 Answers 2

5

No! Don't go this way.

If you want to access server resources from the client-side, you'll need to design and implement a Web service, for example on top of REST principles, which drives you directly to ASP.NET Web API.

In summary: expose resources from the backend using a Web service and access them using AJAX.

Sign up to request clarification or add additional context in comments.

2 Comments

The first line of this answer sums up my initial reaction to this question perfectly!
@DavidWatts Hahaha, I know that everyone will experience the same reaction: "NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO INTEROP NOOOOOOOOOOOOOOO"
0

If I'm not mistaken in guessing, you have a dll that you want to run on the web browser (iirc, only IE). If that's the case, then you have to register the dll on the client computer ( with regsvr, regasm, depending on your dll).

But I agree with Matias, use it as last resort, for example, you have to call this dll for some legacy hardware requirement, legacy app, etc, and you've spent 3 months at least looking for another way. :p

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.