SOAP Server/Client Doesn't Work
#39923807
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
Участник
Откуда: Симферополь
Сообщения: 1 776
|
|
Relic Hunter,
Что-то у Вас совсем с кодом плохо...а где ...wdls у Вас находится...он часто требуется для клиента.
Вот рабочий пример.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22.
const xml = require('fs').readFileSync('webservice.xml', 'utf8');
const http=require("http");
const soap=require("soap");
const url = require("url");
var server = http.createServer(function(request,response) {
//let u = url.parse(request.url);
//console.log(request.headers.host);
response.end('404: Not Found: ' + request.url);
});
server.listen(8000);
server=soap.listen(server, '/webserviceService/webservice', webservice, xml);
server.log = function(type, data) {
// console.log(data,type);
};
server.on('headers', function(headers, methodName) {
console.log(headers,methodName);
});
Важный параметр webservice объявлен Выше.
(я весь код под спойлео положу)
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183.
const parseprocess=require("./util/parsexmlrequest");
const winston = require('winston');
const { format} = require('winston');
//const get_rowbyid=require("./util/utils").get_rowbyid;
const path = require('path');
const now = new Date();
const commonlogfile_name = './log/common-' + now.getFullYear() + "-"+ now.getMonth() + "-" + now.getDate() +'.log';
const filename = path.join(__dirname, commonlogfile_name);
const errorlogfile_name = './log/error-' + now.getFullYear() + "-"+ now.getMonth() + "-" + now.getDate() +'.log';
const filenameerror = path.join(__dirname, errorlogfile_name);
const baseinit=require("./baseadapter/database");
const get_xml=require("./util/get_rowsdifferentformat").get_xml;
winston.loggers.add('common', {
transports: [
new winston.transports.Console({'timestamp':true}),
new winston.transports.File({ filename:filename })
],
format: format.combine(
format.timestamp(),
format.simple()
),
});
winston.loggers.add('error', {
transports: [
new winston.transports.Console({'timestamp':true}),
new winston.transports.File({ filename:filenameerror })
],
format: format.combine(
format.timestamp(),
format.simple()
),
});
const commonlog = winston.loggers.get('common');
const errorlog = winston.loggers.get('error');
module.exports.commonlog=commonlog;
module.exports.errorlog =errorlog ;
commonlog.info("init succesedd");
const webservice = {
webserviceService: {
webservicePort: {
sayHello: function(args) {
console.log(args);
return {
name: args.name
};
},
// This is how to define an asynchronous function.
sqlexecute: function(args) {
const sqlexecute=require("./orabase/sqlexecute").execute;
// do some work
// console.log(args);
// commonlog.info(JSON.stringify(args));
const now = new Date();
// commonlog.info("start-------------------------------------"+now+"--------------------------------------");
// commonlog.info(args.execname);
commonlog.info(args.xmlparams);
// commonlog.info(args.metaxml);
// commonlog.info("end----------------------------------------"+now+"-------------------------------------");
// return {savexmlResponse:"1"};
let sqlparam=parseprocess.parseprocess("document","params",["name","type","v"],args.xmlparams);
// console.log(sqlparam);
let promise= sqlexecute(args.execname,sqlparam);
// let row=get_rowbyid(sqlparam,"oid","name");
// console.log(row);
promise.then((res)=>{callback( {return: res})},(err)=>{
errorlog.error(err);
commonlog.error(err);
callback( {return:-1});
// throw err
});
},
returnbitmap: function(args) {
// do some work
},
get_table: function(args,callback) {
console.log(args);
const get_table=require("./orabase/get_tablesql").get_table;
// const sqlexecute=require("./orabase/get_tablesql").execute;
let sqlparam=parseprocess.parseprocess("document","params",["name","type","v"],args.xmlparams);
let addwhere=parseprocess.parseprocess("document","addwhere",["v"],args.xmlparams);
let set_macro=parseprocess.parseprocess("document","setmacro",["name","v"],args.xmlparams);
console.log("addwhere",addwhere);
let promise= get_table(args.queryname,sqlparam,addwhere,set_macro);
promise.then((rows)=>{
let xmlrows=get_xml("contents",rows);
console.log(xmlrows);
callback( {return: xmlrows})},(err)=>{
errorlog.error(err);
commonlog.error(err);
console.log(err)
callback( {return:err.toString()});
// throw err
});
},
savexml: function(args, callback) {
const sqlexecute=require("./orabase/sqlexecute").execute;
const now = new Date();
commonlog.info(args.xmlparams);
let sqlparam=parseprocess.parseprocess("document","params",["name","type","v"],args.xmlparams);
sqlparam.push({name:"xmlclob",type:"2",v:args.metaxml});
let promise= sqlexecute(args.execname,sqlparam);
promise.then((res)=>{callback( {return: res})},(err)=>{
errorlog.error(err);
commonlog.error(err);
callback( {return:-1});
});
},
// This is how to receive incoming headers
HeadersAwareFunction: function(args, cb, headers) {
return {
name: headers.Token
};
},
// You can also inspect the original `req`
reallyDetailedFunction: function(args, cb, headers, req) {
console.log('SOAP `reallyDetailedFunction` request from ' + req.connection.remoteAddress);
return {
name: headers.Token
};
}
}
}
};
const xml = require('fs').readFileSync('webservice.xml', 'utf8');
const http=require("http");
const soap=require("soap");
const url = require("url");
var server = http.createServer(function(request,response) {
response.end('404: Not Found: ' + request.url);
});
server.listen(8000);
server=soap.listen(server, '/webserviceService/webservice', webservice, xml);
server.log = function(type, data) {
// console.log(data,type);
};
server.on('headers', function(headers, methodName) {
console.log(headers,methodName);
});
baseinit.init();
Он работает с СУБД(лишний код выхолостите) клиент как java так и node
клиент node
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39.
var soap = require('soap');
var configurl=require("../rule/config");
var url = configurl.urls.soapurls;
/*url будет типа
soapurls:'http://192.168.0.100:8082/webserviceService/webservice?wsdl',*/
var soap = require('soap');
//Асинхронный soap
function sendxml_soap(xmlcontents) {
return new Promise( function(resolve, reject) {
let args = {execname: 'frompdaorder',xmlparams:get_xmlparams(),metaxml:xmlcontents};
soap.createClient(url, function (err, client) {
if(err) {reject(err);return;}
client.savexml(args, function (err, result) {
if(err) {reject(err);return;}
console.log(result.return);
resolve(result.return);
});
});
});
}
//ну и попроще тест
function soapsayHello() {
return new Promise( function(resolve, reject) {
let args = {name: "hello"};
soap.createClient(url, function (err, client) {
if(err) {reject(err);return;}
client.sayHello(args, function (err, result) {
if(err) {reject(err);return;}
console.log(result.return);
if(result.return==='work') { resolve(result.return);}
else reject("NO Work");
});
});
});
}
И конечно без файла wdsl soap не существует.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:HolldataIntf-IXmldata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:HolldataIntf-IXmldata" name="webserviceService">
<types>
<xsd:schema>
<xsd:import namespace="urn:HolldataIntf-IXmldata" schemaLocation="shema.xml"/>
</xsd:schema>
</types>
<message name="print">
<part name="parameters" element="tns:print"/>
</message>
<message name="printResponse">
<part name="parameters" element="tns:printResponse"/>
</message>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<message name="get_table">
<part name="parameters" element="tns:get_table"/>
</message>
<message name="get_tableResponse">
<part name="parameters" element="tns:get_tableResponse"/>
</message>
<message name="sqlexecute">
<part name="parameters" element="tns:sqlexecute"/>
</message>
<message name="sqlexecuteResponse">
<part name="parameters" element="tns:sqlexecuteResponse"/>
</message>
<message name="returnbitmap">
<part name="parameters" element="tns:returnbitmap"/>
</message>
<message name="returnbitmapResponse">
<part name="parameters" element="tns:returnbitmapResponse"/>
</message>
<message name="savexml">
<part name="parameters" element="tns:savexml"/>
</message>
<message name="savexmlResponse">
<part name="parameters" element="tns:savexmlResponse"/>
</message>
<portType name="webservice">
<operation name="print">
<input wsam:Action="urn:HolldataIntf-IXmldata:webservice:printRequest" message="tns:print"/>
<output wsam:Action="urn:HolldataIntf-IXmldata:webservice:printResponse" message="tns:printResponse"/>
</operation>
<operation name="sayHello">
<input wsam:Action="urn:HolldataIntf-IXmldata:webservice:sayHelloRequest" message="tns:sayHello"/>
<output wsam:Action="urn:HolldataIntf-IXmldata:webservice:sayHelloResponse" message="tns:sayHelloResponse"/>
</operation>
<operation name="get_table">
<input wsam:Action="urn:HolldataIntf-IXmldata:webservice:get_tableRequest" message="tns:get_table"/>
<output wsam:Action="urn:HolldataIntf-IXmldata:webservice:get_tableResponse" message="tns:get_tableResponse"/>
</operation>
<operation name="sqlexecute">
<input wsam:Action="urn:HolldataIntf-IXmldata:webservice:sqlexecuteRequest" message="tns:sqlexecute"/>
<output wsam:Action="urn:HolldataIntf-IXmldata:webservice:sqlexecuteResponse" message="tns:sqlexecuteResponse"/>
</operation>
<operation name="returnbitmap">
<input wsam:Action="urn:HolldataIntf-IXmldata:webservice:returnbitmapRequest" message="tns:returnbitmap"/>
<output wsam:Action="urn:HolldataIntf-IXmldata:webservice:returnbitmapResponse" message="tns:returnbitmapResponse"/>
</operation>
<operation name="savexml">
<input wsam:Action="urn:HolldataIntf-IXmldata:webservice:savexmlRequest" message="tns:savexml"/>
<output wsam:Action="urn:HolldataIntf-IXmldata:webservice:savexmlResponse" message="tns:savexmlResponse"/>
</operation>
</portType>
<binding name="webservicePortBinding" type="tns:webservice">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="print">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sayHello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="get_table">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sqlexecute">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="returnbitmap">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="savexml">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="webserviceService">
<port name="webservicePort" binding="tns:webservicePortBinding">
<soap:address location="http://localhost:8000/webserviceService/webservice"/>
</port>
</service>
</definitions>
А вот как Вы его сгенерируете ...это другой разговор...у меня была java -soap сервер...и она сама по методам генерирвала эту хрень.
Но java была медленной приглось перевести на node...У меня выбора не было...не знаю зачем вы soap в node потащили, вместо обычного rest http .
soap больше javaвская .netтовская технология ,крайне громоздкая,скложная и как следствие вымирающая
|
|