问题描述
现在需要在js中调用C#的dll,查询网上的资料后说需要编写com组件,于是先写了个简单的com组件做测试,但是asp.net中的js调用时一直报错“对象不支持属性或方法”代码是这样的接口:[ComVisible(true)][Guid("2CBD3D76-35F1-4f9d-9C1B-9DBFEE412F76")]publicinterfaceIHello{stringShowHello();}接口的实现[ComVisible(true)][Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0D")][ProgId("HelloWord.Hello")]publicclassHello:IObjectSafety,IHello{publicstringShowHello(){return"hello";}privateconststring_IID_IDispatch="{00020400-0000-0000-C000-000000000046}";privateconststring_IID_IDispatchEx="{a6ef9860-c720-11d0-9337-00a0c90dcaa9}";privateconststring_IID_IPersistStorage="{0000010A-0000-0000-C000-000000000046}";privateconststring_IID_IPersistStream="{00000109-0000-0000-C000-000000000046}";privateconststring_IID_IPersistPropertyBag="{37D84F60-42CB-11CE-8135-00AA004BB851}";privateconstintINTERFACESAFE_FOR_UNTRUSTED_CALLER=0x00000001;privateconstintINTERFACESAFE_FOR_UNTRUSTED_DATA=0x00000002;privateconstintS_OK=0;privateconstintE_FAIL=unchecked((int)0x80004005);privateconstintE_NOINTERFACE=unchecked((int)0x80004002);privatebool_fSafeForScripting=true;privatebool_fSafeForInitializing=true;publicintGetInterfaceSafetyOptions(refGuidriid,refintpdwSupportedOptions,refintpdwEnabledOptions){intRslt=E_FAIL;stringstrGUID=riid.ToString("B");pdwSupportedOptions=INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA;switch(strGUID){case_IID_IDispatch:case_IID_IDispatchEx:Rslt=S_OK;pdwEnabledOptions=0;if(_fSafeForScripting==true)pdwEnabledOptions=INTERFACESAFE_FOR_UNTRUSTED_CALLER;break;case_IID_IPersistStorage:case_IID_IPersistStream:case_IID_IPersistPropertyBag:Rslt=S_OK;pdwEnabledOptions=0;if(_fSafeForInitializing==true)pdwEnabledOptions=INTERFACESAFE_FOR_UNTRUSTED_DATA;break;default:Rslt=E_NOINTERFACE;break;}returnRslt;}publicintSetInterfaceSafetyOptions(refGuidriid,intdwOptionSetMask,intdwEnabledOptions){intRslt=E_FAIL;stringstrGUID=riid.ToString("B");switch(strGUID){case_IID_IDispatch:case_IID_IDispatchEx:if(((dwEnabledOptions&dwOptionSetMask)==INTERFACESAFE_FOR_UNTRUSTED_CALLER)&&(_fSafeForScripting==true))Rslt=S_OK;break;case_IID_IPersistStorage:case_IID_IPersistStream:case_IID_IPersistPropertyBag:if(((dwEnabledOptions&dwOptionSetMask)==INTERFACESAFE_FOR_UNTRUSTED_DATA)&&(_fSafeForInitializing==true))Rslt=S_OK;break;default:Rslt=E_NOINTERFACE;break;}returnRslt;}}调用的时候<htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title><scriptlanguage="javascript"type="text/javascript">functionTest(){varmyAx=document.getElementById("t");if(myAx!=null){vars=myAx.ShowHello();alert(s);}}</script></head><body><objectclassid="clsid:EA2F140A-108F-47AE-BBD5-83EEE646CC0D"id="t"style="width:0;height:0"></object><formid="form1"runat="server"><div><asp:TextBoxrunat="server"ID="txtPass"Width="500px"Height="400px"TextMode="MultiLine"></asp:TextBox><asp:Buttonrunat="server"Text="计算密码"ID="btnCalPass"OnClick="btnCalPass_Click"/><asp:Buttonrunat="server"Text="客户端计算密码"OnClientClick="Test();"/></div></form></body></html>请帮忙看看是哪里出问题了呢?
解决方案
解决方案二:
没报错,没环境,看不出来,帮顶。