node-soap icon indicating copy to clipboard operation
node-soap copied to clipboard

Error parsing WSDL

Open giesse opened this issue 14 years ago • 10 comments

Using the following WSDL: https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.26.wsdl

I get the following error:

TypeError: Cannot read property 'elements' of undefined at [object Object].postProcess (node_modules/soap/lib/wsdl.js:328:66) at [object Object].postProcess (node_modules/soap/lib/wsdl.js:361:17) at [object Object].postProcess (node_modules/soap/lib/wsdl.js:377:15) at [object Object].postProcess (node_modules/soap/lib/wsdl.js:390:14) at [object Object].postProcess (node_modules/soap/lib/wsdl.js:422:21) at node_modules/soap/lib/wsdl.js:555:36 at [object Object].processIncludes (node_modules/soap/lib/wsdl.js:597:9) at Array.1 (node_modules/soap/lib/wsdl.js:550:14) at EventEmitter._tickCallback (node.js:192:40)

(That was by running a simple soap.createClient with the given URL.)

giesse avatar May 02 '12 18:05 giesse

Fixed. Thanks for submitting the bug report. (npm seems to be down temporarily so for now you will have to grab the latest code from git rather than using 'npm update')

milewise avatar May 02 '12 19:05 milewise

Awesome! I just tried it and noticed that client.describe() returns this:

{ TransactionProcessor: { portXML: { runTransaction: undefined } } }

Is that to be expected? (ie. is CyberSource missing something in their WSDL?)

giesse avatar May 03 '12 09:05 giesse

@giesse This is expected. It's on my TO DO list to output the correct format of the input and output messages for operations defined in the WSDL. The WSDL will still work fine.

milewise avatar May 04 '12 05:05 milewise

There are more issues with this service, let me know if you want me to create separate issues here:

  • The server fails if the namespace is not specified on each tag
  • They are using attributes, which I'm not sure you support yet

More details: their documentation is somewhat hard to figure out, but they have working examples in other languages: http://www.cybersource.com/support_center/implementation/downloads/soap_api/SOAP_toolkits.pdf

I've been using their PHP sample as a reference as it was easy to set up. This is what the PHP sample is sending out:

<ns1:requestMessage>
  <ns1:merchantID>v8221326</ns1:merchantID>
  <ns1:merchantReferenceCode>PHP test</ns1:merchantReferenceCode>
  <ns1:clientLibrary>PHP</ns1:clientLibrary>
  <ns1:clientLibraryVersion>5.3.5</ns1:clientLibraryVersion>
  <ns1:clientEnvironment>Linux store1 2.6.37.6-0.11-default #1 SMP 2011-12-19 23:39:38 +0100 i686</ns1:clientEnvironment>
  <ns1:billTo>
    <ns1:firstName>John</ns1:firstName>
    <ns1:lastName>Doe</ns1:lastName>
    <ns1:street1>1295 Charleston Road</ns1:street1>
    <ns1:city>Mountain View</ns1:city>
    <ns1:state>CA</ns1:state>
    <ns1:postalCode>94043</ns1:postalCode>
    <ns1:country>US</ns1:country>
    <ns1:email>[email protected]</ns1:email>
    <ns1:ipAddress>10.7.111.111</ns1:ipAddress>
  </ns1:billTo>
  <ns1:item id="0">
    <ns1:unitPrice>12.34</ns1:unitPrice>
    <ns1:quantity>2</ns1:quantity>
  </ns1:item>
  <ns1:item id="1">
    <ns1:unitPrice>56.78</ns1:unitPrice>
  </ns1:item>
  <ns1:purchaseTotals>
    <ns1:currency>USD</ns1:currency>
  </ns1:purchaseTotals>
  <ns1:card>
    <ns1:accountNumber>4111111111111111</ns1:accountNumber>
    <ns1:expirationMonth>12</ns1:expirationMonth>
    <ns1:expirationYear>2020</ns1:expirationYear>
  </ns1:card>
  <ns1:ccAuthService run="true"/>
</ns1:requestMessage>

This is what I get out of the box using your library:

<data:requestMessage>
  <merchantID>v8221326</merchantID>
  <merchantReferenceCode>node.js test</merchantReferenceCode>
  <clientLibrary>node.js SOAP</clientLibrary>
  <clientLibraryVersion>0.2.3</clientLibraryVersion>
  <clientEnvironment>Linux imac.giesse 3.2.0-2-amd64 #1 SMP Sun Mar 4 22:48:17 UTC 2012 x86_64 GNU/Linux</clientEnvironment>
  <ccAuthService>
    <run>true</run>
  </ccAuthService>
  <billTo>
    <firstName>John</firstName>
    <lastName>Doe</lastName>
    <street1>1295 Charleston Road</street1>
    <city>Mountain View</city>
    <state>CA</state>
    <postalCode>94043</postalCode>
    <country>US</country>
    <email>[email protected]</email>
    <ipAddress>10.7.111.111</ipAddress>
  </billTo>
  <card>
    <accountNumber>4111111111111111</accountNumber>
    <expirationMonth>12</expirationMonth>
    <expirationYear>2020</expirationYear>
  </card>
  <purchaseTotals>
    <currency>USD</currency>
  </purchaseTotals>
  <item>
    <unitPrice>12.34</unitPrice>
    <quantity>2</quantity>
    <id>0</id>
  </item>
  <item>
    <unitPrice>56.78</unitPrice>
    <id>1</id>
  </item>
</data:requestMessage>

I was able to get the namespace into each tag with a simple change to your code, adding the namespace argument to the recursion in the objectToXML function:

        parts.push(self.objectToXML(item, name, namespace));

I'm not sure if this should the default, or whether there should be an option for it to cope with services like this one (is it a bug on their side, or is the namespace really required on each tag?).

The other problem are the tag attributes (run="true" and id="xxx"). You can see them in the XSD, and I assume that's just not supported yet; do you think this would be a lot of work to add? I might be able to work on it on my spare time if you give me pointers. (I have to get this running quickly, so I may have to go with some ugly workaround in the mean time, or resort to using PHP to talk to this service if other issues come up.)

(Note, they require an account in order to test the service, unfortunately. But, let me know if you want me to test anything.)

giesse avatar May 04 '12 09:05 giesse

It also appears that the tags need to be in a specific order. Once the order is correct and the attributes are correct (I'm using a simple workaround for that), the service works correctly.

giesse avatar May 04 '12 10:05 giesse

thanks giesse. will take a look at this as soon as i get a chance. by the way, describe() now works properly in the latest version of node-soap

milewise avatar May 09 '12 06:05 milewise

hello @giesse I've also faced the problem you're facing, specifically the "run" part like what you mentioned "The other problem are the tag attributes (run="true" and id="xxx"). You can see them in the XSD"

it would be great if you could let me know how do you sort that out, like maybe provide some code examples? I think many others have this problem too.

thanks!

dimilau avatar Feb 28 '14 09:02 dimilau

I'm not actively using this library anymore (the project relying on that service has been scrapped). I assume the code has improved a lot since then; however, what I did to get it working is the following:

This is the patch I was applying to node-soap:

diff --git a/lib/wsdl.js b/lib/wsdl.js
index e480d38..142b3a5 100644
--- a/lib/wsdl.js
+++ b/lib/wsdl.js
@@ -802,27 +802,46 @@ WSDL.prototype.objectToRpcXML = function(name, params, namespace, xmlns) {
     return parts.join('');
 }

+function prepTagAttributes(obj) {
+    var attrs = [], _attrs = {};
+    if (Array.isArray(obj) && (obj.length > 0) && (typeof obj[0] === 'object') && (typeof obj[0]._attrs === 'object')) {
+        _attrs = obj[0]._attrs;
+    } else if ((typeof obj === 'object') && (typeof obj._attrs === 'object')) {
+        _attrs = obj._attrs;
+    }
+    for (var attrname in _attrs) {
+        var attrvalue = _attrs[attrname];
+        attrs.push([' ',attrname,'="',xmlEscape(attrvalue),'"'].join(''));
+    }
+    return attrs;
+}
+
 WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns) {
     var self = this,
         parts = [],
         xmlnsAttrib = false ? ' xmlns:'+namespace+'="'+xmlns+'"'+' xmlns="'+xmlns+'"' : '',
-        ns = namespace ? namespace + ':' : '';
+        ns = namespace ? namespace + ':' : '',
+        attrs;

     if (Array.isArray(obj)) {
         for (var i=0, item; item=obj[i]; i++) {
             if (i > 0) {
+                attrs = prepTagAttributes(item);
                 parts.push(['</',ns,name,'>'].join(''));
-                parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
+                parts.push(['<',ns,name,xmlnsAttrib,attrs.join(''),'>'].join(''));
             }
-            parts.push(self.objectToXML(item, name));
+            parts.push(self.objectToXML(item, name, namespace));
         }
     }
     else if (typeof obj === 'object') {
         for (var name in obj) {
-            var child = obj[name];
-            parts.push(['<',ns,name,xmlnsAttrib,'>'].join(''));
-            parts.push(self.objectToXML(child, name));
-            parts.push(['</',ns,name,'>'].join(''));
+            if (name != '_attrs') {
+                var child = obj[name];
+                attrs = prepTagAttributes(child);
+                parts.push(['<',ns,name,xmlnsAttrib,attrs.join(''),'>'].join(''));
+                parts.push(self.objectToXML(child, name, namespace));
+                parts.push(['</',ns,name,'>'].join(''));
+            }
         }
     }
     else if (obj) {

So, basically, I was putting attributes in an object named _attrs and then having node-soap put that into tag attributes.

giesse avatar Feb 28 '14 13:02 giesse

Has this been fixed? I am having this issue with an Oracle-WebLogic-based service that I don't control the wsdl namespaces.

I have tried ignoring ns1 namespace, but does not seem to work.

turbogeek avatar Sep 26 '14 16:09 turbogeek

+1! same problem of turbogeek with Oracle-WebLogic

v4l3r10 avatar Jul 08 '15 02:07 v4l3r10