简体   繁体   English

启用AJAX的WCF服务功能可重定向到新窗口

[英]AJAX enabled WCF Service function to redirect to a new window

Scenario : I am going to access external web service [ExternalWS] using AJAX. 场景 :我将使用AJAX访问外部Web服务[ExternalWS]。 So obviously, need to create local proxy service [LocalProxyWS] first, which in turn will access the external web service. 因此很明显,首先需要创建本地代理服务[LocalProxyWS],然后它将访问外部Web服务。 Now, the external service webmethod [Process] basically redirects the current page on our site to their site, does some work and then return back to our site. 现在,外部服务webmethod [Process]基本上将我们网站上的当前页面重定向到他们的网站,进行一些工作,然后返回到我们的网站。

What I want : I want that when the user clicks the button ('Process') on our site, it should open a new window and then starts executing the request on the new window, so that I can have the page on my website to be displayed permanently (which will poll a request every 15 seconds to the external service (via local proxy) for the status). 我想要的是 :我希望当用户单击我们网站上的按钮(“处理”)时,它应该打开一个新窗口,然后开始在新窗口上执行请求,以便我可以将网站上的页面会永久显示(这将每15秒轮询一次请求(通过本地代理)到外部服务的状态)。

Hope I am clear in my explanation. 希望我的解释清楚。

Below is my code so far, please feel free to comment if there is any other way which is an efficient alternative.. 下面是到目前为止的代码,如果有其他方法可以作为一种有效的替代方法,请随时发表评论。

Local Proxy service which calls external service is as follows.. 调用外部服务的本地代理服务如下。

    [ServiceContract(Namespace = "LocalProxy")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LocalProxyToExternalService
{
    [OperationContract]
    public void InitiateTransaction(string amount)
    {
        //NOTE: Basically want to call the external service from here in 
                a new window.....
        //HttpContext.Current.Response.Redirect("www.google.com", false);
    }
}

My Page code is as follows... 我的页面代码如下...

        function PayWithXYZ() {

         var newWindow = window.open('', '_blank', 'width=500,height=500', false);
         newWindow.focus();

        var service = new LocalProxy.LocalProxyToExternalService();
        service.InitiateTransaction($('input[id*=TextBox1]').val());   //, OnPayWithXYZCompleted, OnPayWithXYZError);
    }

    function OnPayWithXYZCompleted(result) {
        $('span[id*=Label1]').text(result);            
    }

    function OnPayWithXYZError(result) {
        alert(result.get_message());
    }

</script>


<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/Services/LocalProxyToExternalService.svc" />
    </Services>
</asp:ScriptManager>   


<div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Pay with XYZ" OnClick="Button1_Click" />
    <input id="Button2" type="button" value="Client Button" onclick="PayWithXYZ();" />
</div>
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="Label"></asp:Label>

Basically, I am opening a new window from the button click and then want to process the new request in that new window, so that I can show the status to the user from the current page on my website 基本上,我要通过单击按钮打开一个新窗口,然后想在该新窗口中处理新请求,以便可以从网站上的当前页面向用户显示状态

So far, it opens the new window, but doesn't transfer the request on to that, but I get an error message in firebug as follows... 到目前为止,它会打开新窗口,但不会将请求转移到该窗口,但是我在firebug中收到如下错误消息... 在此处输入图片说明

Web Services as such don't have any UI and so all your web service calls from browser would be in back-ground - so I am not clear about the need to execute service in new window - IMO, its simply not needed. 这样的Web服务没有任何UI,因此您从浏览器进行的所有Web服务调用都处于后台-因此,我不清楚是否需要在新窗口中执行服务-IMO,根本不需要。

Your error message indicates that your web service InitiateTransaction does not return correct data. 您的错误消息表明您的Web服务InitiateTransaction没有返回正确的数据。 What is the implementation of that method. 该方法的实现是什么。 IMO, it should be invoking a external web service - either by using service proxy (created by Add Service Reference if its SOAP service) or by using WebClient/WebRequest (if it is REST based service). IMO,它应该调用外部Web服务-通过使用服务代理(如果是SOAP服务,则由“添加服务引用”创建),或者通过使用WebClient / WebRequest(如果是基于REST的服务)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM