Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a SOAP Webservice With node-soap

I followed this example of the git repo (https://github.com/vpulim/node-soap):

Questions 1

I already created a server Is it necessary to create the server in the callback. From my understanding readFileSync is anyways blocking.

Question 2

Wouldn't it be better to write non blocking and put soap.listen into the callback

Question 3

Where do I get: 'myservice.wsdl'. Do I have to create it/ How to create it? Is there a generator?

soap.service.coffee

 exports.getService = () ->
  myService = {
    MyService: {
      MyPort: {

        # This is how to define an asynchronous function.
        MyAsyncFunction: (args, callback) ->
          # do some work
          callback({
            name: args.name
          })
      }
    }
  }

exports.getXml = () ->
  require('fs').readFileSync('myservice.wsdl', 'utf8', ()->
    server = http.createServer((request,response) ->
      response.end("404: Not Found: "+request.url)
    )
  )

server.coffee

...

http = require('http')
portHTTP = process.env.PORT || 61361
io = require('socket.io')
soap = require('soap')
soapService = require('./backend/soap/soap.service.js')

...

server = http.createServer(app).listen(portHTTP, () ->
  logger.info("Unsecure Express server listening on port #{portHTTP} environment: #{environment}")
)
soap.listen(server, '/wsdl', soapService.getService, soapService.getXml)
like image 213
Andi Giga Avatar asked Mar 10 '26 12:03

Andi Giga


1 Answers

Answer to question 1: readFileSync is used to load the wsdl not to create the server. So it is not necessary to create server in callback.

Answer to question 2: soap.listen is listening for a request and then that is processed. It is the # do some work step that could be blocking hence the callback after that step.

Answer to question 3: You have to either create your wsdl when writing your SOAP API server or if you are using an existing service it should be provided for use in the form of a url ending in wsdl.

The wsdl is in xml and so could be generated. See which wsdl style to use notes.

Also see my soap example project nodejs_mock_agresso.

like image 78
Ezzye Avatar answered Mar 12 '26 05:03

Ezzye