Skip to content

Commit e6e2553

Browse files
committed
Added functionality to ignore default tns and disabled default tns specification in first element of the body
1 parent 2ed85c7 commit e6e2553

File tree

6 files changed

+203
-2
lines changed

6 files changed

+203
-2
lines changed

lib/wsdl.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ var WSDL = function(definition, uri, options) {
10391039
};
10401040

10411041
WSDL.prototype.ignoredNamespaces = ['tns', 'targetNamespace', 'typedNamespace'];
1042+
WSDL.prototype._ignoredSchemaNamespaces = ['tns', 'xs', 'xsd'];
10421043

10431044
WSDL.prototype.valueKey = '$value';
10441045
WSDL.prototype.xmlKey = '$xml';
@@ -1115,6 +1116,37 @@ WSDL.prototype.describeServices = function() {
11151116
return services;
11161117
};
11171118

1119+
/**
1120+
* Returns true if a schema namespace needs to be ignored.
1121+
*
1122+
* @method shouldIgnoreNamespace
1123+
* @param {Object} schema The parsed WSDL Schema object.
1124+
*/
1125+
WSDL.prototype.shouldIgnoreNamespace = function(schema) {
1126+
if (schema && typeof schema.xmlns === 'object') {
1127+
// get the keys from schema.xmlns object (something like xs, xsd or custom)
1128+
var schemaXmlns = Object.keys(schema.xmlns);
1129+
var schemaXmlnsLength = schemaXmlns.length;
1130+
if (schemaXmlnsLength > 0) {
1131+
var count = 0;
1132+
// loop through the keys
1133+
for (var key in schemaXmlns) {
1134+
var xmlns = schemaXmlns[key];
1135+
// if the key exists in the default ignoredSchemaNamespaces, add it to the count
1136+
if (this._ignoredSchemaNamespaces.indexOf(xmlns) > -1) {
1137+
count++;
1138+
}
1139+
}
1140+
// if the count is equal to the length, don't add the namespace
1141+
if(count === schemaXmlnsLength) {
1142+
return true;
1143+
}
1144+
}
1145+
}
1146+
1147+
return false;
1148+
};
1149+
11181150
WSDL.prototype.toXML = function() {
11191151
return this.xml || '';
11201152
};
@@ -1390,11 +1422,12 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
13901422
var qualified = schema && schema.$elementFormDefault === 'qualified';
13911423
var parts = [];
13921424
var prefixNamespace = (namespace || qualified) && namespace !== 'xmlns';
1425+
var isNamespaceIgnored = this.shouldIgnoreNamespace(schema);
13931426

13941427
var xmlnsAttrib = '';
13951428
if (xmlns && first) {
13961429

1397-
if (prefixNamespace) {
1430+
if (prefixNamespace && (!isNamespaceIgnored || this.ignoredNamespaces.indexOf(namespace) === -1)) {
13981431
// resolve the prefix namespace
13991432
xmlnsAttrib += ' xmlns:' + namespace + '="' + xmlns + '"';
14001433
}
@@ -1410,7 +1443,7 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
14101443
}
14111444

14121445
var ns = '';
1413-
if (prefixNamespace && ((qualified || first) || soapHeader)) {
1446+
if (prefixNamespace && ((qualified || first) || soapHeader) && (!isNamespaceIgnored || this.ignoredNamespaces.indexOf(namespace) === -1)) {
14141447
// prefix element
14151448
ns = namespace.indexOf(":") === -1 ? namespace + ':' : namespace;
14161449
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Items": {
3+
"Item": [{
4+
"ItemNumber": "1234",
5+
"RequestedQuantity": {
6+
"Value": "1.00"
7+
}
8+
}]
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="SAMPLE"><soap:Body><GetItemInformation xmlns="SAMPLE"><Items><Item><ItemNumber>1234</ItemNumber><RequestedQuantity><Value>1.00</Value></RequestedQuantity></Item></Items></GetItemInformation></soap:Body></soap:Envelope>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Items": {
3+
"Item": {
4+
"ItemNumber": "1234",
5+
"RequestedQuantity": {
6+
"Value": "1.00"
7+
}
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="SAMPLE">
3+
<soap:Body>
4+
<GetItemInformationResponse xmlns="SAMPLE">
5+
<Items>
6+
<Item>
7+
<ItemNumber>1234</ItemNumber>
8+
<RequestedQuantity>
9+
<Value>1.00</Value>
10+
</RequestedQuantity>
11+
</Item>
12+
</Items>
13+
</GetItemInformationResponse>
14+
</soap:Body>
15+
</soap:Envelope>
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<wsdl:definitions
3+
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
4+
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
5+
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
6+
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
7+
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
8+
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
9+
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
10+
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
11+
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
12+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
13+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
14+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
15+
xmlns:tns="SAMPLE"
16+
name="SampleService"
17+
targetNamespace="SAMPLE" >
18+
<wsdl:types>
19+
<xs:schema elementFormDefault="qualified" targetNamespace="SAMPLE" xmlns:xs="http://www.w3.org/2001/XMLSchema">
20+
<xs:element name="GetItemInformation">
21+
<xs:complexType>
22+
<xs:sequence>
23+
<xs:element minOccurs="0" maxOccurs="1" name="Items" type="tns:ArrayOfItem" />
24+
</xs:sequence>
25+
</xs:complexType>
26+
</xs:element>
27+
<xs:complexType name="ArrayOfItem">
28+
<xs:sequence>
29+
<xs:element minOccurs="0" maxOccurs="unbounded" name="Item" nillable="true" type="tns:Item" />
30+
</xs:sequence>
31+
</xs:complexType>
32+
<xs:complexType name="Item">
33+
<xs:complexContent mixed="false">
34+
<xs:extension base="tns:ItemBase">
35+
<xs:sequence>
36+
<xs:element minOccurs="0" maxOccurs="1" name="AvailState" type="tns:AvailableState" />
37+
<xs:element minOccurs="0" maxOccurs="1" name="Warehouses" type="tns:ArrayOfWarehouse" />
38+
</xs:sequence>
39+
</xs:extension>
40+
</xs:complexContent>
41+
</xs:complexType>
42+
<xs:complexType name="ItemBase">
43+
<xs:sequence>
44+
<xs:element minOccurs="0" maxOccurs="1" name="ItemNumber" type="xs:string" />
45+
<xs:element minOccurs="1" maxOccurs="1" name="SupplierId" type="xs:short" />
46+
<xs:element minOccurs="0" maxOccurs="1" name="SupplierName" type="xs:string" />
47+
<xs:element minOccurs="0" maxOccurs="1" name="RequestedQuantity" type="tns:Quantity" />
48+
</xs:sequence>
49+
</xs:complexType>
50+
<xs:complexType name="Quantity">
51+
<xs:sequence>
52+
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string" />
53+
<xs:element minOccurs="0" maxOccurs="1" name="Description" type="xs:string" />
54+
<xs:element minOccurs="0" maxOccurs="1" name="AvailState" type="tns:AvailableState" />
55+
<xs:element minOccurs="1" maxOccurs="1" name="Value" type="xs:decimal" />
56+
</xs:sequence>
57+
</xs:complexType>
58+
<xs:complexType name="AvailableState">
59+
<xs:sequence>
60+
<xs:element minOccurs="1" maxOccurs="1" name="AvailState" type="xs:int" />
61+
</xs:sequence>
62+
</xs:complexType>
63+
<xs:complexType name="ArrayOfWarehouse">
64+
<xs:sequence>
65+
<xs:element minOccurs="0" maxOccurs="unbounded" name="Warehouse" nillable="true" type="tns:Warehouse" />
66+
</xs:sequence>
67+
</xs:complexType>
68+
<xs:complexType name="Warehouse">
69+
<xs:sequence>
70+
<xs:element minOccurs="1" maxOccurs="1" name="Default" type="xs:boolean" />
71+
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string" />
72+
</xs:sequence>
73+
</xs:complexType>
74+
<xs:complexType name="ArrayOfQuantity">
75+
<xs:sequence>
76+
<xs:element minOccurs="0" maxOccurs="unbounded" name="Quantity" nillable="true" type="tns:Quantity" />
77+
</xs:sequence>
78+
</xs:complexType>
79+
<xs:element name="GetItemInformationResponse">
80+
<xs:complexType>
81+
<xs:sequence>
82+
<xs:element minOccurs="0" maxOccurs="1" name="GetItemInformationResult" type="tns:GetBackItems" />
83+
</xs:sequence>
84+
</xs:complexType>
85+
</xs:element>
86+
<xs:complexType name="GetBackItems">
87+
<xs:complexContent mixed="false">
88+
<xs:extension base="tns:BaseGetBack">
89+
<xs:sequence>
90+
<xs:element minOccurs="0" maxOccurs="1" name="Items" type="tns:ArrayOfItem" />
91+
</xs:sequence>
92+
</xs:extension>
93+
</xs:complexContent>
94+
</xs:complexType>
95+
<xs:complexType name="BaseGetBack">
96+
<xs:sequence>
97+
<xs:element minOccurs="1" maxOccurs="1" name="ErrorCode" type="xs:int" />
98+
<xs:element minOccurs="0" maxOccurs="1" name="ErrorMessage" type="xs:string" />
99+
</xs:sequence>
100+
</xs:complexType>
101+
</xs:schema>
102+
</wsdl:types>
103+
<wsdl:message name="ISampleService_GetItemInformation_InputMessage">
104+
<wsdl:part name="parameters" element="tns:GetItemInformation" />
105+
</wsdl:message>
106+
<wsdl:message name="ISampleService_GetItemInformation_OutputMessage">
107+
<wsdl:part name="parameters" element="tns:GetItemInformationResponse" />
108+
</wsdl:message>
109+
<wsdl:portType name="ISampleService">
110+
<wsdl:operation name="GetItemInformation">
111+
<wsdl:input wsaw:Action="SAMPLE/ISampleService/GetItemInformation" message="tns:ISampleService_GetItemInformation_InputMessage" />
112+
<wsdl:output wsaw:Action="SAMPLE/ISampleService/GetItemInformationResponse" message="tns:ISampleService_GetItemInformation_OutputMessage" />
113+
</wsdl:operation>
114+
</wsdl:portType>
115+
<wsdl:binding name="BasicHttpBinding_ISampleService" type="tns:ISampleService">
116+
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
117+
<wsdl:operation name="GetItemInformation">
118+
<soap:operation soapAction="SAMPLE/ISampleService/GetItemInformation" style="document" />
119+
<wsdl:input>
120+
<soap:body use="literal" />
121+
</wsdl:input>
122+
<wsdl:output>
123+
<soap:body use="literal" />
124+
</wsdl:output>
125+
</wsdl:operation>
126+
</wsdl:binding>
127+
<wsdl:service name="SampleService">
128+
<wsdl:port name="BasicHttpBinding_SampleService" binding="tns:BasicHttpBinding_ISampleService">
129+
<soap:address location="http://example.com/v1/" />
130+
</wsdl:port>
131+
</wsdl:service>
132+
</wsdl:definitions>

0 commit comments

Comments
 (0)