跨域访问来自javascript的服务

跨域访问来自javascript的服务

本文介绍了跨域访问来自javascript的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们现有的asp net应用程序也包含web服务。此服务标有ScriptService属性。
我们想要的是允许来自"第三方"的jscript的调用。网页。我尝试在名为WebApp2的新Web应用程序中构建asp.net页面,并从中引用此类服务​​,例如 

< form id =" form1" RUNAT = QUOT;服务器"> 
< asp:ScriptManager runat =" server">
<服务>
< asp:ServiceReference Path =" http://< serverName> /WebApp1/services/TestService.asmx" />
< / Services>来自jscript的
< / asp:ScriptManager>

我需要调用它

< script type =" text / javascript"> 
函数updateAlarm(){
var client = new TestPortal.TestService();
var res = client.TestMethod();
}
< / script>

当jscript运行的服务和页面位于同一个Web应用程序时,此方法有效。但是,情况并非如此,并且不起作用。我需要做些什么才能让它运转?

感谢您的帮助

Lubos一定次数

解决方案

Hi,

we have existing asp net application containing also web service. This service is marked with ScriptService attribute.
What we want is to allow calls from jscript from "3rd party" web pages. I tried to build-up asp.net page in new web application called WebApp2 and reference such service from it like 

    <form id="form1" runat="server">
    <asp:ScriptManager runat="server">
        <Services >
            <asp:ServiceReference Path="http://<serverName>/WebApp1/services/TestService.asmx"/>
        </Services>
    </asp:ScriptManager>

from jscript i need to call it

    <script type="text/javascript">
        function updateAlarm() {
            var client = new TestPortal.TestService();
            var res = client.TestMethod();
        }
    </script>

This works when service and page where the jscript runs from are on same web app. However, this is not the case and it doesn't work. What i need to do in order to get it running?

thanks for any help

Lubos



解决方案


这篇关于跨域访问来自javascript的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:27