cross domain access to service from javascript


hi,

we have existing asp net application containing web service. service marked scriptservice attribute.
what want allow calls jscript "3rd party" web pages. tried build-up asp.net page in new web application called webapp2 and reference such service 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 need call it

    <script type="text/javascript">          function updatealarm() {              var client = new testportal.testservice();              var res = client.testmethod();          }          </script>

this works when service , page jscript runs on same web app. however, not case , doesn't work. need in order running?

thanks help

lubos



pure ajax (xmlhttprequest) in forms not support cross domain calls.

but fortunately there workarounds make work, done having page/handler acts proxy on domain makes webrequest external domain , forwards results. can use httpwebrequest , httpwebresponse classes this.

this link provides sample implementation this.
and here link with more details
if dont want make page can use pure javascript make work using http://www.ajax-cross-domain.com/

ps: on side note browsers (obviously @ client side) can tweaked use cross-domain ajax, check this



Archived Forums A-B  >  ASMX Web Services and XML Serialization



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'