jQuery JSONP WCF/ASMX Cross Domain

I spent almost 40 hours to find a single working article but couldn't.  So please be kind and don't just give me a link.  :)  Again, I spend serious time on this and probably i saw and tried every link you can find in Google.

I have a web site which is in US server and web service which is in UK server with IIS7+WS2008

Doesn't matter if solution is ASMX or WCF based as long as there is a solution!

All I want to do is making a simple "HelloWorld" call via simple HTML page with jQuery from US  server to UK server.

Please feel free to reply if you know something about it.

Thank you very much for your time and attention.

cilerlerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KrileCommented:
I am going to guess that you want information on one server (UK) to be "fed" to information on another server (US) using some sort of AJAX technology (jQuery).  If my assumptions are correct, the short answer is you cannot do this directly.  

So, you either need to write code on your US server that queries the UK server (this is allowed on the server-side), or add another library to your mix : http://www.ajax-cross-domain.com/

leakim971PluritechnicianCommented:
example here work for me fine : http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax

The proxy which really do the call to the web service : http://www.webservicex.net/CurrencyConvertor.asmx

Save this file as : callservice.aspx




<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" Debug="true" %>
<%
	XmlDocument wsResponse = new XmlDocument();
        string url =  "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=" + Request.QueryString["FromBox"].ToString() + "&ToCurrency=" + Request.QueryString["ToBox"].ToString();
        wsResponse.Load(url);
        string XMLDocument = wsResponse.InnerXml;
        Response.ContentType = "text/xml";
        Response.Write(XMLDocument);
%>

Open in new window

leakim971PluritechnicianCommented:
The main page : Default.htm


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication16._Default" %>

<!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">
<title>test</title>
<script language="javascript" type="text/javascript">
    var xmlhttprequest = null;

    function initiateConversion() {
        xmlhttprequest = createRequestObject();
        var url = "callservice.aspx?FromBox="+ document.getElementById("FromBox").value+ "&ToBox=" + document.getElementById("ToBox").value;
        xmlhttprequest.open("GET", url, true);
        xmlhttprequest.onreadystatechange = getData;
        xmlhttprequest.send(null);
    }

function createRequestObject() 
{
        if (window.XMLHttpRequest) 
        {
                return xmlhttprequest = new XMLHttpRequest(); 
        } 
      else if (window.ActiveXObject) 
      {  
            return xmlhttprequest = new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
}
function getData() 
{
  if ((xmlhttprequest.readyState == 4) &&( xmlhttprequest.status == 200))
  {
    var myXml = xmlhttprequest.responseXML;
    var xmlobject = null;
    var XMLText = null;
    if (window.ActiveXObject)
    {
        XMLText = myXml.childNodes[1].firstChild.nodeValue; 
    }
    else
    {
        XMLText = myXml.childNodes[0].firstChild.nodeValue;
    }
    
    var table = document.getElementById("table1");
    var row = table.insertRow(table.rows.length);
    var tablecell = row.insertCell(row.cells.length);
    tablecell.appendChild(document.createTextNode(document.getElementById("FromBox").value + " to " + document.getElementById("ToBox").value));
    var tablecell = row.insertCell(row.cells.length);
    tablecell.appendChild(document.createTextNode(XMLText));
    table.setAttribute("border", "2");
  } 
}
</script>
</head>
<body>
Currency To Convert From:
<select id="FromBox">
<option value="USD" selected="selected">USD - U.S. Dollar</option>
<option value="GBP">GBP - British Pound</option>
<option value="EUR">EUR - Euro</option>
<option value="JPY">JPY - Japanese Yen</option>
</select>
Currency To Convert To:
<select id="ToBox">
<option value="USD">USD - U.S. Dollar</option>
<option value="GBP" selected="selected">GBP - British Pound</option>
<option value="EUR">EUR - Euro</option>
<option value="JPY">JPY - Japanese Yen</option>
</select>
<br /><br />
<input id="button1" type="button" value="Click to convert currency" onclick="initiateConversion()" />
<br /><br />
<table id="table1">
</table>
</body>
</html>

Open in new window

CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

leakim971PluritechnicianCommented:
Put the two file in same web folder.
Tested on MS Windows Server 2008 with Chrome, IE, Safari, Opera and Firefox
cilerlerAuthor Commented:
@skrile: thx for your time but not the answer I was looking for.
@leakin971: big thank you for your time and attention.  It should work but it is kind of a workaround.  Which is not working for me.  And the article was great thx for that.

If anyone wants to learn how to handle this with .Net4 please check http://goo.gl/SPw1

Thanks again.

Best

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve KrileCommented:
I was clearly in over my head with this question.  But, I learned something!  Thanks for posting that .net 4 link.  JSONP sounds a bit scary and I'm not convinced there aren't more serious cross-site security issues, but it does solve the problem of getting data from out there into here.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WCF

From novice to tech pro — start learning today.