本文介绍了使用 Node-soap 或 Strong-soap 时,如何获取要提供给客户端的服务器 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 node.js 的 node-soap 包编写服务.当我执行node myService.js"时,该服务似乎运行正常.现在,我如何获取将提供给客户端的 url?如果你想要我的 wsdl 文件,myservice.wsdl"按照下面的代码,请告诉我.这是我的代码

var http = require('http');var soap = require('soap');var express = require('express');var bodyParser = require('body-parser');var myService = {我的服务:{我的端口:{post_csvDoc:函数(csvDoc){返回 200;},post_jsonDoc:函数(csvDoc){返回 200;},post_pdfDoc:函数(csvDoc){返回 200;},get_csvDoc:函数(月){返回 "FirstDoc";},get_jsonDoc:函数(月){返回 "SecondDoc";},get_pdfDoc:函数(月){返回 "ThirdDoc";},}}};var xml = require('fs').readFileSync('myservice.wsdl', 'utf8');//http服务器示例var server = http.createServer(function(request,response) {response.end('404: Not Found: ' + request.url);});服务器.听(8000);soap.listen(服务器,'/wsdl',myService,xml);//快速服务器示例var app = express();//支持body解析器中间件(可选)app.use(bodyParser.raw({type: function(){return true;}, limit: '5mb'}));app.listen(8001, 函数(){//注意:/wsdl路由将由soap模块处理//和所有其他路线 &中间件将继续工作soap.listen(app, '/wsdl', myService, xml);});

这是我在尝试

抱歉,我没有刷新堆栈溢出,因此没有看到您对 wsdl 的请求.wsdl下方:

<!--布拉姆龙2018-06-23让您通过 SOAP 协议发布/检索在线文档在线 WSDL 1.1 SOAP 生成器 0.2朱利安·布利特--><definitions name="让您通过 SOAP 发布/检索在线文档协议"targetNamespace="bramron.group.company.project.plateform.documentservice.wsdl"><!--数据类型的定义 --><类型><架构targetNamespace="bramron.group.company.project.plateform.documentservice.xsd"><elementname="csvDoc"><complexType><all><element name="value"type="string"/></all></complexType></element><elementname="jsonDoc"><complexType><all><element name="value"type="string"/></all></complexType></element><elementname="pdfDoc"><complexType><all><element name="value"type="string"/></all></complexType></element><elementname="returnCode"><complexType><all><element name="value"type="int"/></all></complexType></element><elementname="月"><消息名称="returns_returnCode"><部分name="returnCode" type="xsd:returnCode"/></message><messagename="returns_csvDoc"><part name="csvDoc"type="xsd:csvDoc"/></message><message name="returns_jsonDoc"><partname="jsonDoc" type="xsd:jsonDoc"/></message><messagename="returns_pdfDoc"><part name="pdfDoc"type="xsd:pdfDoc"/></message><!-- 请求消息--><消息name="post_csvDoc"><part name="csvDoc"type="xsd:csvDoc"/></message><message name="post_jsonDoc"><partname="jsonDoc" type="xsd:jsonDoc"/></message><messagename="post_pdfDoc"><part name="pdfDoc"type="xsd:pdfDoc"/></message><message name="get_csvDoc"><partname="month" type="xsd:month"/></message><messagename="get_jsonDoc"><part name="月"type="xsd:month"/></message><message name="get_pdfDoc"><partname="month" type="xsd:month"/></message><!-- 服务器的服务--><portType name="Document"><operation name="post_csvDoc"><inputmessage="tns:post_csvDoc"/><outputmessage="tns:returns_returnCode"/></operation><operationname="post_jsonDoc"><input message="tns:post_jsonDoc"/><outputmessage="tns:returns_returnCode"/></operation><operationname="post_pdfDoc"><input message="tns:post_pdfDoc"/><outputmessage="tns:returns_returnCode"/></operation><operationname="get_csvDoc"><input message="tns:get_csvDoc"/><outputmessage="tns:returns_csvDoc"/></operation><operationname="get_jsonDoc"><input message="tns:get_jsonDoc"/><outputmessage="tns:returns_jsonDoc"/></operation><operationname="get_pdfDoc"><input message="tns:get_pdfDoc"/><outputmessage="tns:returns_pdfDoc"/></operation></portType><!-- 服务器编码 --><binding name="Document_webservices"type="tns:Document"><soap:binding style="rpc"transport="http://schemas.xmlsoap.org/soap/http"/><operationname="post_csvDoc"><soap:operationsoapAction="urn:xmethods-delayed-quotes#post_csvDoc"/><input><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operationname="post_jsonDoc"><soap:operationsoapAction="urn:xmethods-delayed-quotes#post_jsonDoc"/><input><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operationname="post_pdfDoc"><soap:operationsoapAction="urn:xmethods-delayed-quotes#post_pdfDoc"/><input><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operationname="get_csvDoc"><soap:operationsoapAction="urn:xmethods-delayed-quotes#get_csvDoc"/><input><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operationname="get_jsonDoc"><soap:operationsoapAction="urn:xmethods-delayed-quotes#get_jsonDoc"/><input><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operationname="get_pdfDoc"><soap:operationsoapAction="urn:xmethods-delayed-quotes#get_pdfDoc"/><input><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:bodyuse="encoded" namespace="urn:xmethods-delayed-quotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation></binding><!--访问服务提供商 --><服务名称=生产"><端口name="production_0" binding="Document_webservices"><soap:addresslocation="http://127.0.0.1:8000/document_soap/endpoint1"/></port><portname="production_1" binding="Document_webservices"><soap:addresslocation="http://127.0.0.1:8000/document_soap/endpoint2"/></port></service></definitions>

总结:对于任何有兴趣的人,这个问题的答案是:

  1. 使用 http://127.0.0.1:8001/wsdl?wsdl 作为网址而不仅仅是 http://127.0.0.1:8001/wsd
  2. 根据 Terry 发布的 dropbox wsdl 链接在定义标签中添加命名空间.谢谢特里.请参阅下面的移动到聊天"
解决方案

您的服务 URL 将为 http://您的域:8000/wsdl.如果你在本地运行,这将是 http://localhost:8000/wsdl,因为在这种情况下你已将您的端口号设置为 8000.在这种情况下,您实际上还运行了两台服务器,因此您也将拥有 prot 8001!

I am writing a service with node.js' node-soap package. The service seem to run okay when I do "node myService.js". Now, how do I get the url that would be given to the client? If you want my wsdl file, "myservice.wsdl" as per the code below please let me know. here is my code

var http = require('http');
var soap = require('soap');
var express = require('express');
var bodyParser = require('body-parser');

var myService = {
     MyService: {
         MyPort: {
             post_csvDoc: function(csvDoc) {
                 return 200;
             },
             post_jsonDoc: function(csvDoc) {
                 return 200;
             },
             post_pdfDoc: function(csvDoc) {
                 return 200;
             },
             get_csvDoc: function(month) {
                 return "FirstDoc";
             },
             get_jsonDoc: function(month) {
                 return "SecondDoc";
             },
             get_pdfDoc: function(month) {
                 return "ThirdDoc";
             },
         }
     }
};

var xml = require('fs').readFileSync('myservice.wsdl', 'utf8');

//http server example
var server = http.createServer(function(request,response) {
    response.end('404: Not Found: ' + request.url);
});

server.listen(8000);
soap.listen(server, '/wsdl', myService, xml);

//express server example
var app = express();
//body parser middleware are supported (optional)
app.use(bodyParser.raw({type: function(){return true;}, limit: '5mb'}));
app.listen(8001, function(){
    //Note: /wsdl route will be handled by soap module
    //and all other routes & middleware will continue to work
    soap.listen(app, '/wsdl', myService, xml);
});

This is the error I get when I enter path when I try http://127.0.0.1:8001/wsdl?wsdl:

Sorry I did not refresh stack overflow and as such did not see your request for the wsdl. Below the wsdl:

<!-- 
Bramron
2018-06-23
let you post/retrieve online documents by SOAP protocol

Online WSDL 1.1 SOAP generator 0.2
Julien Blitte
 
--><definitions name="let you post/retrieve online documents by SOAP 
protocol" 
targetNamespace="bramron.group.company.project.plateform.documentservice.wsdl"><!-- 
definition of datatypes --> <types><schema 
targetNamespace="bramron.group.company.project.plateform.documentservice.xsd"><element 
name="csvDoc"><complexType><all><element name="value" 
type="string"/></all></complexType></element><element 
name="jsonDoc"><complexType><all><element name="value" 
type="string"/></all></complexType></element><element 
name="pdfDoc"><complexType><all><element name="value" 
type="string"/></all></complexType></element><element 
name="returnCode"><complexType><all><element name="value" 
type="int"/></all></complexType></element><element 
name="month"><complexType><all><element name="value" 
type="int"/></all></complexType></element></schema></types><!-- 
response messages --> <message name="returns_returnCode"><part 
name="returnCode" type="xsd:returnCode"/></message><message 
name="returns_csvDoc"><part name="csvDoc" 
type="xsd:csvDoc"/></message><message name="returns_jsonDoc"><part 
name="jsonDoc" type="xsd:jsonDoc"/></message><message 
name="returns_pdfDoc"><part name="pdfDoc" 
type="xsd:pdfDoc"/></message><!-- request messages --> <message 
name="post_csvDoc"><part name="csvDoc" 
type="xsd:csvDoc"/></message><message name="post_jsonDoc"><part 
name="jsonDoc" type="xsd:jsonDoc"/></message><message 
name="post_pdfDoc"><part name="pdfDoc" 
type="xsd:pdfDoc"/></message><message name="get_csvDoc"><part 
name="month" type="xsd:month"/></message><message 
name="get_jsonDoc"><part name="month" 
type="xsd:month"/></message><message name="get_pdfDoc"><part 
name="month" type="xsd:month"/></message><!-- server's services --> 
<portType name="Document"><operation name="post_csvDoc"><input 
message="tns:post_csvDoc"/><output 
message="tns:returns_returnCode"/></operation><operation 
name="post_jsonDoc"><input message="tns:post_jsonDoc"/><output 
message="tns:returns_returnCode"/></operation><operation 
name="post_pdfDoc"><input message="tns:post_pdfDoc"/><output 
message="tns:returns_returnCode"/></operation><operation 
name="get_csvDoc"><input message="tns:get_csvDoc"/><output 
message="tns:returns_csvDoc"/></operation><operation 
name="get_jsonDoc"><input message="tns:get_jsonDoc"/><output 
message="tns:returns_jsonDoc"/></operation><operation 
name="get_pdfDoc"><input message="tns:get_pdfDoc"/><output 
message="tns:returns_pdfDoc"/></operation></portType><!-- server 
encoding --> <binding name="Document_webservices" 
type="tns:Document"><soap:binding style="rpc" 
transport="http://schemas.xmlsoap.org/soap/http"/><operation 
name="post_csvDoc"><soap:operation 
soapAction="urn:xmethods-delayed-quotes#post_csvDoc"/><input><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation 
name="post_jsonDoc"><soap:operation 
soapAction="urn:xmethods-delayed-quotes#post_jsonDoc"/><input><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation 
name="post_pdfDoc"><soap:operation 
soapAction="urn:xmethods-delayed-quotes#post_pdfDoc"/><input><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation 
name="get_csvDoc"><soap:operation 
soapAction="urn:xmethods-delayed-quotes#get_csvDoc"/><input><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation 
name="get_jsonDoc"><soap:operation 
soapAction="urn:xmethods-delayed-quotes#get_jsonDoc"/><input><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation 
name="get_pdfDoc"><soap:operation 
soapAction="urn:xmethods-delayed-quotes#get_pdfDoc"/><input><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body 
use="encoded" namespace="urn:xmethods-delayed-quotes" 
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation></binding><!-- 
access to service provider --> <service name="production"><port 
name="production_0" binding="Document_webservices"><soap:address 
location="http://127.0.0.1:8000/document_soap/endpoint1"/></port><port 
name="production_1" binding="Document_webservices"><soap:address 
location="http://127.0.0.1:8000/document_soap/endpoint2"/></port></service></definitions>

Summary: for anyone who is interested, the answer to this question is:

  1. Using http://127.0.0.1:8001/wsdl?wsdl as the url instead of just http://127.0.0.1:8001/wsd
  2. adding the namespaces in the definitions tag as per the dropbox wsdl link posted by Terry. Thanks Terry. See "moved to chat" below
解决方案

Your service URL will be http://your-domain:8000/wsdl. If you're running locally this will be http://localhost:8000/wsdl, since in this case you've set your port number to 8000. In this case you've actually got two servers running as well so you'll have prot 8001 as well!

这篇关于使用 Node-soap 或 Strong-soap 时,如何获取要提供给客户端的服务器 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 15:14