简体   繁体   English

具有Javascript客户端(AngularJS)的Azure服务总线中继

[英]azure service bus relay with Javascript client (AngularJS)

We are implementing Azure Service Bus Relay to consume WCF services and we have successfully consumed services using service bus from ASP.NET MVC application. 我们正在实现Azure服务总线中继以使用WCF服务,并且已经使用ASP.NET MVC应用程序中的服务总线成功使用了服务。

We want to consume this services using Azure Service Bus Relay from AngularJS. 我们想使用来自AngularJS的Azure Service Bus Relay使用此服务。

Is there any way to access Azure Service Bus from AngularJS? 有什么方法可以从AngularJS访问Azure Service Bus? or do we need to write extra API layer to consume services using service bus? 还是我们需要编写额外的API层才能使用服务总线使用服务?

Please provide guideline and pointers. 请提供指南和指示。

No you can't connect to a Service Bus Relay from AngularJS code since JavaScript only supports making Ajax calls through HTTP, where the Service Bus Relay communicates through a TCP connection without using HTTP. 不,您无法从AngularJS代码连接到服务总线中继,因为JavaScript仅支持通过HTTP进行Ajax调用,其中服务总线中继通过TCP连接进行通信,而无需使用HTTP。

You will need to write server-side code in your application that connects to and communicates to the WCF services through the Azure Service Bus Relay. 您将需要在应用程序中编写通过Azure Service Bus Relay连接到WCF服务并与之通信的服务器端代码。 Then you can expose whatever data and functionality you need to your AngularJS code by making Ajax calls from client-side AngularJS code to the server-side web application. 然后,您可以通过从客户端AngularJS代码到服务器端Web应用程序进行Ajax调用,来向AngularJS代码公开所需的任何数据和功能。

You have a Web Application that runs on the server anyway, so integrating this should not be an issue for you. 无论如何,您都有一个在服务器上运行的Web应用程序,因此集成此应用程序对您来说不是问题。

The layer and call stack outline would be: 层和调用堆栈的轮廓为:

  1. AngularJS code calls back to Web App it's hosted within AngularJS代码回调到托管在其中的Web App

  2. Ajax call to Web App connects to Service Bus Relay Web应用程序的Ajax调用连接到服务总线中继

  3. Service Bus Relay communicates with WCF service 服务总线中继与WCF服务通信

  4. WCF service handled method call and returns response WCF服务处理的方法调用并返回响应

  5. Service Bus Relay send WCF method response back to Web App 服务总线中继将WCF方法响应发送回Web App

  6. Web App returns Ajax response to AngularJS code Web App返回Ajax对AngularJS代码的响应

  7. AngularJS receives Ajax response and does what it needs to as a result. AngularJS收到Ajax响应并执行所需的操作。

Additionally, if you could call the Service Bus Relay directly from the AngularJS / JavaScript code in your Web Application, you would still have cross-domain origin issues since the Service Bus Relay is hosted on a different domain than your Web Application. 此外,如果您可以直接从Web应用程序中的AngularJS / JavaScript代码调用服务总线中继,则由于服务总线中继位于与Web应用程序不同的域上,因此您仍然会遇到跨域起源问题。

Try using the WebHttpRelayBinding for your service to consume it via HTTP: 尝试为您的服务使用WebHttpRelayBinding以通过HTTP使用它:

https://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.webhttprelaybinding.aspx https://msdn.microsoft.com/zh-CN/library/azure/microsoft.servicebus.webhttprelaybinding.aspx

The CORs issue that @Chris Pietschmann brought up is still valid here. @Chris Pietschmann提出的CORs问题在这里仍然有效。 Not sure if Relay will flow that header through if your service sets it. 如果您的服务设置了中继,不确定中继是否会通过该头部。 Also make sure that you allow unauthenticated users -- you don't want to expose your security token =) 还要确保您允许未经身份验证的用户-您不想公开您的安全令牌=)

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

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