Home  >  Q&A  >  body text

javascript - nodejs调用wcf服务

一个小作业,目前有一个在本机上用nodejs调用本机wcf服务的一个需求,但是目前我还没搞明白wcf到底是个啥...看网上的说明也看不太懂,以前都是直接post接口...

从网上的wcf.js主页上看到这样代码:

 var BasicHttpBinding = require('wcf.js').BasicHttpBinding
      , Proxy = require('wcf.js').Proxy
      , binding = new BasicHttpBinding(
            { SecurityMode: "TransportWithMessageCredential"
            , MessageClientCredentialType: "UserName"
            })
      , proxy = new Proxy(binding, "http://localhost:7171/Service/clearUsername")
      , message =  "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" +
                     "<Header />" +
                       "<Body>" +
                         "<GetData xmlns='http://tempuri.org/'>" +
                           "<value>123</value>" +
                         "</GetData>" +
                        "</Body>" +
                   "</Envelope>"

    proxy.ClientCredentials.Username.Username = "yaron"
    proxy.ClientCredentials.Username.Password = "1234"

    proxy.send(message, "http://tempuri.org/IService/GetData", function(response, ctx) {
      console.log(response)
    });

没搞明白这段代码的意思,以及这里面两个网址和XML都是干什么的?

目前我本机上只有一个这个东西:

感觉还是比较乱...求老司机帮忙解释解释代码并且普及下wcf到底是个啥,在此谢过啦

迷茫迷茫2724 days ago335

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-10 17:47:00

    WCF是微软的通信协议,使用类似WSDL的文档来描述接口,通常与WebService相似,部分操作可以兼容WebService、Web API调用,与http,tcp绑定居多。由于复杂度高,这几年已经逐渐被restful代替。举个栗子,restful Web API没有oai文档的情况下仍然可以快速理解,但是wcf就算给你文档,你也不明白啥意思,何况wcf的接口描述文档比WSDL更复杂。

    reply
    0
  • Cancelreply