首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

调用另一台电脑IIS5.1下的WCF服务

2013-01-04 
调用另一台电脑IIS5.1上的WCF服务一个简单的WCF服务,两个数相加,然后将它承载在了另一台电脑的IIS5.1上。在

调用另一台电脑IIS5.1上的WCF服务
  一个简单的WCF服务,两个数相加,然后将它承载在了另一台电脑的IIS5.1上。在我的电脑(和那天电脑一个局域网)上有一个WebSite,利用
  (1)Web服务引用,可以成功调用那个WCF服务。
  (2)利用调用svcutil.exe生成相应的代理类也可以在网页中调用那个WCF服务。
  现在想实现利用
   <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
            <asp:ScriptReference Path="~/Scripts/WcfService.js" />
        </Scripts>
        </asp:ScriptManager>
   以及相应的代码:
<script type="text/javascript">
    // <![CDATA[

    // This function creates an asynchronous call to the service
    function makeCall(operation) {
        var n1 = document.getElementById("num1").value;
        var n2 = document.getElementById("num2").value;

        // If user filled out these fields, call the service
        if (n1 && n2) {

            // Instantiate a service proxy
           microsoft.samples.gettingstarted.icalculator.Add(parseFloat(n1),
                    parseFloat(n2), onSuccess, onFail, null);
                     }
   
   // This function is called when the result from the service call is received
    function onSuccess(mathResult) {
        document.getElementById("result").value = mathResult;
    }

    // This function is called if the service call fails
    function onFail() {
        document.getElementById("result").value = "Error";
    }
          
    </script>

   js代码是利用:http://另一台机子的主机名/ServiceModelSamples/service.svc/js生成的。

但是每次都显示Error??怎么回事呢,谢谢
[解决办法]
WCF服务端需要支持跨域。

查查 WCF 跨域

热点排行