从Javascript调用Web服务 - 它是什么引擎盖下做什么?引擎盖、做什么、它是、Javascript

2023-09-06 07:10:48 作者:像個笑話

最近一位同事不得不从脚本中调用.NET 2.0的Web服务。我们注意到,我们不得不把[ScriptService]属性,可以通过AJAX扩展或升级到3.5。

Recently a colleague had to call a .NET 2.0 web service from script. We noticed that we'd have to put the [ScriptService] attribute, either via AJAX extensions or upgrading to 3.5.

这就是我已经能够发现 - 没有人解释了它的引擎盖下做

That's all I've been able to find out - no-one explains what it's doing under the hood!

任何人都可以告诉我吗?

Can anyone enlighten me?

谢谢 邓肯

推荐答案

从严格意义上讲,你不需要为了使从脚本调用做任何事情到Web服务。

Strictly speaking, you don't need to do anything to a web service in order to make it callable from script.

下面请参见: How使用VBScript来调用Web服务(同步)?

Web服务仅仅是一个系统,该系统通过远程协议,通常是基于Web的协议addressible。通常情况下,这意味着HTTP。一个简单的请求可以只经由一个HTTP GET上执行一个特定的URL - 在URL的路径或所述查询字符串的段组成的参数到web服务请求。

A web service is just a system that is addressible via remote protocols, usually web-based protocols. Often that means HTTP. A simple request can just be performed via an HTTP GET on a particular URL - the segments in the URL path or the query string make up the "parameters" to the web service request.

一个客户端可能会发送一个HTTP GET来

A client might send an HTTP GET to

http://server/appPath/p1/p2/p3

和应用听力会有负责拆包的URL,也许映射P1,P2,P3进入查询参数,然后决定如何回应。

And the application listening there would be responsible for unpacking that URL, maybe mapping the p1, p2, p3 into query parameters, and then determining how to respond to it.

有关更复杂的要求,该事务可以是HTTP POST,和有效载荷的格式是XML,JSON或应用程序指定别的东西。

For more complex requests, the transaction might be HTTP POST, and the format of the payload is either XML, JSON, or something else that your application specifies.

在这种情况下,URL可能像这样:

In this case the URL may be like so:

http://server/appPath/resource1

和POST'd有效载荷,如果使用JSON,可能是:

and the POST'd payload, if using JSON, might be:

{"Age":35,"FirstName":"Peyton","LastName":"Manning"} 

如果使用XML,它可能是:

if using XML, it might be:

<person>
  <Age>35</Age>
  <FirstName>Peyton</FirstName>
  <LastName>Manning</LastName>
</person>

您可以形成一个符合这些限制在任何编程语言,包括像JavaScript脚本的请求。

You can form a request that complies to those constraints in any programming language, including script like Javascript.

如果您使用的是SOAP,那么XML文档需要被包装在SOAP信封。 的例子看到的VBScript 调用WCF服务(VBScript中,但容易翻译为Javascript) 。

If you are using SOAP, then that XML document needs to be wrapped in a SOAP envelope. See Calling WCF service by VBScript for an example (VBScript, but easily translatable to Javascript).

 
精彩推荐
图片推荐