node. JS WebService

Source: Internet
Author: User
Tags wsdl

As a result of the project needs, to understand and use the WebService service, in the online query, WebService is characterized by the implementation of cross-platform, but I need to emulate a server side and client, a variety of information to find ~ ~ ~

Personal experience, do not spray--------------

In node. js, the SOAP module can be found in webservice, but I end up not using the SOAP module, but rather the Soap-server module building server. In soap it is necessary to define a WSDL file itself, in fact, this file is to define what the server provides services (methods), and the input format and output format of each method, I do not use this way, so no wordy. Soap-server Module Building server, the way is very simple, do not need to define the WSDL file itself, it will be automatically generated, there are examples in the module, no longer examples here. The essence of WebService is actually an HTTP server, but it will define a webservice access path on the HTTP server, not to mention it clearly, for example:

  var soap = require (' Soap-server ');  function Mytestservice () {    }  MyTestService.prototype.test1 = function (myArg1) {     return myArg1 + ' 123456 ';  } ;  var soapserver = new soap. SoapServer ();  var soapservice = soapserver.addservice (' Testservice ', New Mytestservice ());  Soapserver.listen (8888);
Note: Here is soap-server encapsulated, but in essence, the HTTP service listens on port 8888, WebService is the access path to receive/testservice, that is, when access is: Http://xxxx:8888/testService , the service goes to webservice, and if the specified method is test1, then the function is executed:
MyTestService.prototype.test1 = function (myArg1) {     return myArg1 + ' 123456 ';  };


The above is the service-side program, now say how the client access, WebService service in node is basically the use of SOAP protocol access, the essence of soap is HTTP and Xml,path designated as the path in WebService, here is:/testservice. There are two different ways to access normal http:

1) Headers need to specify SOAPAction: function name (name of the function to be accessed, Test1 here)

2) The data format is XML and is XML in SOAP format, as follows:

var xml = ' <?xml version= ' 1.0 ' encoding= ' utf-8 '?> ' + ' <soap:envelope xmlns:xsi= ' http://www.w3.org/2001/ Xmlschema-instance "xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "xmlns:soap=" http://schemas.xmlsoap.org/soap/ envelope/"> ' + ' <soap:Body> ' + ' <test1 xmlns=" http://localhost:8888/"> ' + ' <myArg1> ' krime ' </ Myarg1> ' + ' </test1> ' + ' </soap:Body> ' + ' </soap:Envelope> ';
Then follow the normal HTTP access to access, I test is to use the Post method.


node. JS WebService

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.