Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

node.js - 用Express和Soap处理肥皂服务器最终在404中(Handling a soap server with express and soap ends up in 404)

I have been attempting to create a soap server with express and the package soap for the past few days.

(过去几天,我一直在尝试使用express和package soap创建一个soap服务器。)

I used the snippets provided by the library to get started but I'm always getting a 404.

(我使用了库提供的摘录来开始使用,但是我总是得到404。)

The server is like the following:

(服务器如下所示:)

    var xml = require('fs').readFileSync('./soap-service/MyService.wsdl', 'utf8');
    var express = require('express');
    var soap = require('soap');
    var soap_service = require('./soap-service/index.js');
    var bodyParser = require('body-parser');


    var app = express();

    const http = require('http');
    const port = process.env.PORT || 4000;

    // view engine setup
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'hbs');

    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended: false}));
    app.use(cookieParser());
    app.use(express.static(path.join(__dirname, 'public')));
    app.disable('etag')
    app.use(function (req, res, next) {
      res.setHeader('Access-Control-Allow-Origin', '*');
      res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
      res.setHeader('Access-Control-Allow-Methods', 'POST, GET, PATCH, PUT, DELETE, OPTIONS');
      next();
    });

    app.use(express.static(path.join(__dirname, "client", "build")))

    var url = 'http://localhost:4000/wsdl?wsdl';
    const post_soap_request = () => soap.createClient(url, {}, function (err, client) {
      if (!err) {
        var args = { name: 'nameValue' };
        client.MyFunction(args, function (err, result) {
          console.log({ result });
        });

      }
    });

    app.use(bodyParser.raw({ type: function () { return true; }, limit: '5mb' }));

    app.listen(port, function() {
      console.log('Server working on port ' + port);
      const soap_server = soap.listen(app, '/wsdl', soap_service, xml, function (err, result) {
        post_soap_request();
      });
      soap_server.log = function (type, data) {
        console.log({ type, data });
      };
    });

The soap_service imported from ./soap-service/index.js

(从./soap-service/index.js导入的soap_service)

var myService = {
  MyService: {
    MyPort: {
      MyFunction: function (args) {
        return {
          name: 'COUCOU'
        };
      },
    }
  }
};

module.exports = myService;

and the WSDL file:

(和WSDL文件:)

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions
      name="MyService"
      targetNamespace="http://localhost:4000/wsdl/MyService.wsdl"
      xmlns="http://schemas.xmlsoap.org/wsdl/"
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:tns="http://localhost:4000/wsdl/MyService.wsdl"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >

       <message name="MyFunctionRequest">
          <part name="name" type="xsd:string"/>
       </message>
       <message name="MyFunctionResponse">
          <part name="status" type="xsd:string"/>
       </message>
       <portType name="MyPort">
          <operation name="MyFunction">
             <input message="tns:MyFunctionRequest"/>
             <output message="tns:MyFunctionResponse"/>
          </operation>
       </portType>

       <binding name="MyFunction_Binding" type="tns:MyPort">
          <soap:binding style="rpc"
             transport="http://schemas.xmlsoap.org/soap/http"/>
          <operation name="MyFunction">
             <soap:operation soapAction="MyFunction"/>
             <input>
                <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:MyService" use="encoded"/>
             </input>
             <output>
                <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:MyService" use="encoded"/>
             </output>
          </operation>
       </binding>

       <service name="MyService">
          <documentation>WSDL File for MyService</documentation>
          <port binding="tns:MyFunction_Binding" name="MyPort">
             <soap:address location="http://localhost:4000/MyFunction" />
          </port>
       </service>

    </definitions>

I have the same problem from using SOAPUI or the post_soap_request function, the server response is

(我在使用SOAPUI或post_soap_request函数时遇到相同的问题,服务器响应为)

POST /MyFunction 404 2.179 ms
  ask by Defranos translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...