How to call COM Interop of an C# Class,methods using javascript -


i created com interop of c# class access interop usng javascript. class contains addition() method method can not access in javascript.

code below

interface imathinterface

namespace ccwtest {     [guid("756892a0-1242-4bf7-984d-c13e68000e8e")]     [comvisible(true)]     [interfacetype(cominterfacetype.interfaceisidispatch)]     public interface imathinterface     {         [dispid(1)]         int addition(int i, int j);     } } 

class classmath

[guid("ca9ad3a7-bd31-4be2-a780-8864d493ba5f")] [comvisible(true)] [classinterface(classinterfacetype.none)] [progid("ccwtest.classmath")] public class classmath : imathinterface {     [comvisible(true)]     public int addition(int x, int y)     {         return x + y;     } } 

then created snk file ccwmathtest.snk register gacutil. create tlb file using regasm command.all these thing done successfully.

then create web application access class method javascript.

code

<%@ page language="c#" autoeventwireup="true" codebehind="webform1.aspx.cs" inherits="webapplication1.webform1" %>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <object classid="clsid:ca9ad3a7-bd31-4be2-a780-8864d493ba5f" height="0" width="0"         id="obj7" name="obj7">     </object>        <title></title>     <script type="text/javascript">         window.onload = onload;         function onload() {              alert(obj7.addition(3,1));          }     </script> </head> <body>     <form id="form1" runat="server">     <div>     </div>     </form> </body> </html> 

while running code gives me error "object doesn't support property or method 'addition'" how can access method in javascript using com interop

why calling javascript? make webmethod on page, calls com object, , call mehod via ajax javascript. this:

//server side [webmethod] public static string dosomething() {     //call com     return "something"; }  //client side $.ajax({     type: "post",     url: "page.aspx/dosomething",     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: onsuccess,     failure: function (response) {         alert(response.d);         },         error: function (response) {             alert(response.d);         } }); 

Comments

Popular posts from this blog

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -