gpt4 book ai didi

node.js - 使用 Node-soap 或 Strong-soap 时如何获取服务器 url 提供给客户端

转载 作者:太空宇宙 更新时间:2023-11-04 00:08:42 25 4
gpt4 key购买 nike

我正在使用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 = {
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);
});

这是我尝试 http://127.0.0.1:8001/wsdl?wsdl 输入路径时遇到的错误:

enter image description here

抱歉,我没有刷新堆栈溢出,因此没有看到您对 wsdl 的请求。在 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>

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

  1. 使用http://127.0.0.1:8001/wsdl?wsdl作为 url 而不是 http://127.0.0.1:8001/wsd
  2. 按照 Terry 发布的 dropbox wsdl 链接在定义标记中添加 namespace 。谢谢特里。请参阅下面的“移至聊天室”

最佳答案

您的服务 URL 将为 http://your-domain:8000/wsdl 。如果您在本地运行,这将是 http://localhost:8000/wsdl ,因为在本例中您已将端口号设置为 8000。在本例中,您实际上也运行了两台服务器,因此您也将拥有 prot 8001!

关于node.js - 使用 Node-soap 或 Strong-soap 时如何获取服务器 url 提供给客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50987471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com