Creating a SOAP Webservice With node-soap

久未见 提交于 2019-12-23 18:23:05

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/32480481/creating-a-soap-webservice-with-node-soap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!