-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Js-code from lib/model.js gets included in SOAP-request causing SOAP-fault #1412
Comments
I can't help but think this has something to do with the XMLParser and the conversion from JS object to JSON to XML. But until now I cannot quite put my finger on the issue. |
@jmmeijer Can you post your WSDL with XSDs here? |
@jmmeijer As per the stack trace, I see that you are getting a response from your Web Service and it's a Fault response and the Fault response message from your web service is |
@rashmihunt Thank you for your fast reply! It seems there is no XSD defined for the WSDL. I was trying to post to method getDeelnemer, which has two parameters: apiSleutel and deelnemernummer. This is the request format generated by SoapUI: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://api.algemeen.webservices.eduarte.topicus.nl/">
<soapenv:Header/>
<soapenv:Body>
<api:getDeelnemer>
<!--Optional:-->
<apiSleutel>xxx</apiSleutel>
<deelnemernummer>xxx</deelnemernummer>
</api:getDeelnemer>
</soapenv:Body>
</soapenv:Envelope> This returns valid response from the webservice. This is the JSON that the Strongloop API Explorer proposes, which seems correspond with the SOAP XML. {
"apiSleutel": "string",
"deelnemernummer": 0
} Here are links to the WSDL: |
@rashmihunt The problem is similar to or the same as the issue i referred to. A complete SOAP request is posted over there. The problem is a part of the JS-code from /lib/model.js gets included in the SOAP request. Somehow the object of ModelBaseClass is converted to SOAP xml including some of the code to initiate its properties. This is how __cachedRelations (a protected propertyof the model) gets converted to |
@rashmihunt Something goes wrong after the method jsonToXML gets called: strong-soap:client client request. inputBodyDescriptor: {
"elements": [
{
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "apiSleutel"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "string"
},
"form": "unqualified",
"isMany": false,
"isSimple": true,
"refOriginal": {
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "apiSleutel"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "string"
},
"form": "unqualified",
"isMany": false,
"isSimple": true
}
},
{
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "deelnemernummer"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "int"
},
"form": "unqualified",
"isMany": false,
"isSimple": true,
"refOriginal": {
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "deelnemernummer"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "int"
},
"form": "unqualified",
"isMany": false,
"isSimple": true
}
}
],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "getDeelnemer"
},
"type": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "getDeelnemer"
},
"form": "qualified",
"isMany": false,
"isSimple": false,
"typeDescriptor": {
"elements": [
{
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "apiSleutel"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "string"
},
"form": "unqualified",
"isMany": false,
"isSimple": true,
"refOriginal": {
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "apiSleutel"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "string"
},
"form": "unqualified",
"isMany": false,
"isSimple": true
}
},
{
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "deelnemernummer"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "int"
},
"form": "unqualified",
"isMany": false,
"isSimple": true,
"refOriginal": {
"elements": [],
"attributes": [],
"qname": {
"nsURI": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"name": "deelnemernummer"
},
"type": {
"nsURI": "http://www.w3.org/2001/XMLSchema",
"name": "int"
},
"form": "unqualified",
"isMany": false,
"isSimple": true
}
}
],
"attributes": [],
"name": "getDeelnemer",
"xmlns": "http://api.algemeen.webservices.eduarte.topicus.nl/",
"isSimple": false
}
} strong-soap:client client request, calling jsonToXml. args: {
"apiSleutel": "xxx",
"deelnemernummer": 000
} |
@rashmihunt Upon further investigation I found out, that |
Hi, |
@jmmeijer or @rashmihunt: This only seems to affect models created using lb soap as creating the calls to the Soap Webservice yourself as described in e.g. in the strongloop blog seems to work. I'm asking due to trying to evaluate whether it is worth it manually creating the soap calls until the fix will be available as lb soap would make this much easier. |
Fyi @william-santos-bwti @rashmihunt So the model methods inside server/models/.js would look like:
For one of the two soap services I tested though i had to additionally drill down to the first layer of the parsed object as it was otherwise added twice. So i did: It seems like the problem arises because the inputObject somehow either gets additional properties while the object is parsed to xml or the additional properties are ignored when doing JSON.stringify(). Hope this helps anyone and looking forward to updates. |
Hi, @ExTheSea |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump to prevent this issue from being closed. Eventhough several workarounds have been proposed, this issue has not yet been resolved and persists in latest version. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello @rashmihunt, are you still involved? If this is not the case, could this ticket be reassigned to someone else? |
I updated the latest dependencies, but still the same error. my dependencies part of package.json is below.
When I invoke an endpoint on loopback-explorer like The error message of backend console is.
|
After reading up on ES6 I believe this issue might have to do with an object prototype which is iterated over with a for ... in loop for conversion to SOAP causing the methods of this object to be included. In this case using for...of loop would be preferable. Hope this helps! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Another bump in order to prevent this issue from being closed by stale bot. |
@raymondfeng , could you please help? |
Object instances of LoopBack models need to be converted to plain object using toJSON() or toObject() before passing to json2xml. |
I am still facing the same issue. Getting created unwanted <__cachedRelations/>\n <__data> for every child node, I tried both toJSON and toObject but still the same. Spending like 3 days now to figure this out, Like tried almost everything suggested here, Could you please help me? If you need more details I can provide. FYI I have generated the models using CLI, lb soap [WSDL local file] AccountCreationAccountCreationSoap.AccountCreation = function(AccountCreation, callback) {
} Thanks in advance |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump in order to prevent issue from being closed without solution... |
This error has been open for a year? Is it likely to be fixed ever? trying to test on a simple SOAP service http://www.dneonline.com/calculator.asmx . it's posting junk to the service. |
@jmmeijer Reading through some of the ideas here , I don't know if this fixes the overall bug , but changing https://github.com/strongloop/loopback-soap/blob/master/lib/codegen/model.ejs , line 30 to +
I just added the .toObject() seems to fix it for me so I can generate objects that will work. |
@martyjt You can send a pr to fix this issue. |
@liudonghua123 Sorry , I don't have time to learn about test coverage / create tests for this. It is really just to help out. I am not familar with github. |
@martyjt As far as I can tell strong-soap is being used instead of loopback-soap. However I did find similar code that is being used in the swagger API Explorer: https://github.com/strongloop/loopback-swagger/blob/master/lib/codegen/model.ejs |
Please note that models backed by a service connectors (soap, REST, remote) must be configured with I believe To change the base model in an existing codebase, open the model JSON file (e.g. - "base": "PersistedModel"
+ "base": "Model" With this change in place, your model instance should no longer have extra persistence-related properties like |
Copied from Gitter:
|
Just to mention few things: I still have this bug with this package.json:
I used I double check what @bajtos said, all models are generated as "Models", for example :
Finally, I tried what @ExTheSea proposed, and it finally worked. So my binding model is like this now: /**
* MessageSplitter
* @param {MessageSplitterSoapIn} MessageSplitterSoapIn MessageSplitterSoapIn
* @callback {Function} callback Callback function
* @returns {any} callback containing error or result. Result is the response/soap body in JSON form.
*/
MessageSplitterServiceMessageSplitterServiceSoapBinding.MessageSplitter = function(MessageSplitterSoapIn, callback) {
MessageSplitterServiceMessageSplitterServiceSoapBinding.MessageSplitter(JSON.parse(JSON.stringify(MessageSplitterSoapIn)), function(err, response) {
var result = response;
callback(err, result);
});
}; |
@ThomasVuillaume Hi, thanks for your working code. Could you paste the full code of binding model js. I have an empty function like this
|
Finally, I find the code is in |
@liudonghua123 @ThomasVuillaume @ExTheSea I have also succesfully implemented the suggested code.
EDIT: I apologize for not testing thoroughly before commenting. I got an error when using only JSON.parse. A JS-object gets passed to the SoapBinding method which seems to be exactly the same after stringifing and parsing JSON... why then won't it work with the passed object?
Output:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This bug has not yet been resolved. Bump to keep the issue active. Until Loopback 4 has a implementation for autodiscovery and model generation for SOAP, this is still a viable solution. |
I am afraid we don't have bandwidth to address this issue. @jmmeijer would you like to contribute the fix yourself? We are happy to help you along the way. See https://loopback.io/doc/en/contrib/code-contrib.html to get started. |
Steps to reproduce
I have auto discovered a SOAP 1.1 Webservice with
lb soap
and Loobback created models as expected. However when using the StrongLoop API explorer, the SOAP requests fail as they are not properly formatted.Stack trace
When enabling the debug on
loopback:persisted-model
I can see the SOAP xml is cluttered by code originating fromstrongloop/loopback-datasource-juggler
as is mentioned in issue 77 from loopback-connecter-soap by @liudonghua123. Since the code is in this repo I thought it would be best to open an issue here.Expected result
I would expect the SOAP request to be properly formatted. And a SOAP response without an error.
Additional information
win32 x64 6.11.0
+-- loopback@3.8.0
+-- loopback-boot@2.24.1
+-- loopback-component-explorer@2.7.0
+-- loopback-connector-soap@4.0.0
+-- loopback-datasource-juggler@3.9.1
The text was updated successfully, but these errors were encountered: