Popular New Releases in SOAP
node-soap
Version 0.39.0
savon
v2.12.1
soap-client
Version 1.7.0
laravel-soap
PHP8 support
PackageGenerator
4.1.5 - PHP 7.4
Popular Libraries in SOAP
by vpulim javascript
2737 MIT
A SOAP client and server for node.js.
by savonrb ruby
1988 MIT
Heavy metal SOAP client
by mvantellingen python
1583 NOASSERTION
A modern/fast python SOAP client based on lxml / requests
by hooklift go
885 MPL-2.0
WSDL2Go code generation as well as its SOAP proxy
by apache java
758 Apache-2.0
Apache CXF
by phpro php
597 MIT
A general purpose SOAP client for PHP
by notfalsedev php
571 MIT
A soap client wrapper for Laravel
by fiorix go
395 NOASSERTION
Command line tool to generate Go code from WSDL for SOAP XML services
by WsdlToPhp php
339 MIT
Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
Trending New libraries in SOAP
by Ricorocks-Digital-Agency php
244 MIT
A Laravel SOAP client that provides a clean interface for handling requests and responses.
by CodeDredd php
111 MIT
Laravel Soap Client
by SAP go
85 Apache-2.0
SAP BTP service operator enables developers to connect Kubernetes clusters to SAP BTP accounts and to consume SAP BTP services within the clusters by using Kubernetes native tools.
by quarkiverse java
56 Apache-2.0
Quarkus CXF Extension to support SOAP based web services.
by netwo-io rust
21
A SOAP client generator for Rust
by RedHatQE python
18 MIT
Python wrapper for the Polarion WSDL API
by Dlubal-Software python
18 MIT
Python client (or high-level functions) for RFEM 6 using Web Services, SOAP and WSDL
by nikolic-bojan csharp
17
Make SOAP requests using IHttpClientFactory in .NET Core
by shumonsharif java
17 Apache-2.0
Quarkus CXF Extension to support SOAP based web services.
Top Authors in SOAP
1
6 Libraries
22
2
5 Libraries
193
3
5 Libraries
393
4
4 Libraries
117
5
4 Libraries
2108
6
3 Libraries
91
7
3 Libraries
392
8
3 Libraries
98
9
2 Libraries
42
10
2 Libraries
8
1
6 Libraries
22
2
5 Libraries
193
3
5 Libraries
393
4
4 Libraries
117
5
4 Libraries
2108
6
3 Libraries
91
7
3 Libraries
392
8
3 Libraries
98
9
2 Libraries
42
10
2 Libraries
8
Trending Kits in SOAP
No Trending Kits are available at this moment for SOAP
Trending Discussions on SOAP
ServiceStack SOAP support extension
How can I make JavaFX re-initialize when Scene is swapped?
WSDL - allow different order of DataMembers for SOAP messages
unable to consume SOAP service in zeep, python
how to edit the response fields in node-soap
Anypoint Studio problem with JSON into XML transformation
Estes Express Api Version 4.0 Rate Quote
Creating Frontend-Backend connection through Mule ESB
Quickbooks Web Connector "Response is not well-formed XML" error
PowerShell - how to escape {} in JSON string for a REST call
QUESTION
ServiceStack SOAP support extension
Asked 2022-Apr-08 at 13:52will ServiceStack extends support for SOAP service in .NET 6? We’ve seen from documentation that SoapFormat plug-in requires .NET Framework
ANSWER
Answered 2022-Apr-08 at 13:52SOAP Support requires full WCF support which has no plans on being made available on .NET 6 so SOAP Support will be limited to .NET Framework.
We recommend adopting Add ServiceStack Reference which enables a much faster & cleaner superior end-to-end development model for all its 9 supported languages.
QUESTION
How can I make JavaFX re-initialize when Scene is swapped?
Asked 2022-Mar-10 at 12:25I want to make a very simple program in JavaFX. It goes like this:
The user inputs something into a TextField
The program displays the input on a label but on a different Scene
Here is my code:
Controller.java
1package sample;
2
3import javafx.fxml.FXML;
4import javafx.fxml.FXMLLoader;
5import javafx.scene.Parent;
6import javafx.scene.Scene;
7import javafx.scene.control.Label;
8import javafx.scene.control.TextField;
9import javafx.stage.Stage;
10
11import javax.xml.soap.Text;
12import java.io.IOException;
13
14public class Controller {
15
16 //textField in sample.fxml
17 @FXML
18 TextField textField;
19
20 //label in display.fxml
21 @FXML
22 Label label;
23
24 String text;
25
26 @FXML
27 public void enter() throws IOException {
28 text = textField.getText();
29
30 Stage stage = (Stage) (textField).getScene().getWindow();
31
32 Parent root = FXMLLoader.load(getClass().getResource("display.fxml"));
33 stage.setResizable(false);
34 stage.setTitle("Display");
35 stage.setScene(new Scene(root, 300, 275));
36
37 label.setText(text);
38 }
39}
40
Main.java
1package sample;
2
3import javafx.fxml.FXML;
4import javafx.fxml.FXMLLoader;
5import javafx.scene.Parent;
6import javafx.scene.Scene;
7import javafx.scene.control.Label;
8import javafx.scene.control.TextField;
9import javafx.stage.Stage;
10
11import javax.xml.soap.Text;
12import java.io.IOException;
13
14public class Controller {
15
16 //textField in sample.fxml
17 @FXML
18 TextField textField;
19
20 //label in display.fxml
21 @FXML
22 Label label;
23
24 String text;
25
26 @FXML
27 public void enter() throws IOException {
28 text = textField.getText();
29
30 Stage stage = (Stage) (textField).getScene().getWindow();
31
32 Parent root = FXMLLoader.load(getClass().getResource("display.fxml"));
33 stage.setResizable(false);
34 stage.setTitle("Display");
35 stage.setScene(new Scene(root, 300, 275));
36
37 label.setText(text);
38 }
39}
40package sample;
41
42import javafx.application.Application;
43import javafx.fxml.FXMLLoader;
44import javafx.scene.Parent;
45import javafx.scene.Scene;
46import javafx.stage.Stage;
47
48public class Main extends Application {
49
50 @Override
51 public void start(Stage primaryStage) throws Exception{
52 Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
53 primaryStage.setTitle("Hello World");
54 primaryStage.setScene(new Scene(root, 300, 275));
55 primaryStage.show();
56 }
57
58 public static void main(String[] args) {
59 launch(args);
60 }
61}
62
There are 2 other FXML files containing either a single textField or a single Label.
But whenever I run this code there is a NullPointerException signaling that label is null, because it hasn't been initialized. How do I fix this?
ANSWER
Answered 2022-Mar-10 at 12:25I believe you should make antoher controller for the display.fxml file (the other scene). Than in this new controller you can prepare a function to set label value:
DisplayController.java
1package sample;
2
3import javafx.fxml.FXML;
4import javafx.fxml.FXMLLoader;
5import javafx.scene.Parent;
6import javafx.scene.Scene;
7import javafx.scene.control.Label;
8import javafx.scene.control.TextField;
9import javafx.stage.Stage;
10
11import javax.xml.soap.Text;
12import java.io.IOException;
13
14public class Controller {
15
16 //textField in sample.fxml
17 @FXML
18 TextField textField;
19
20 //label in display.fxml
21 @FXML
22 Label label;
23
24 String text;
25
26 @FXML
27 public void enter() throws IOException {
28 text = textField.getText();
29
30 Stage stage = (Stage) (textField).getScene().getWindow();
31
32 Parent root = FXMLLoader.load(getClass().getResource("display.fxml"));
33 stage.setResizable(false);
34 stage.setTitle("Display");
35 stage.setScene(new Scene(root, 300, 275));
36
37 label.setText(text);
38 }
39}
40package sample;
41
42import javafx.application.Application;
43import javafx.fxml.FXMLLoader;
44import javafx.scene.Parent;
45import javafx.scene.Scene;
46import javafx.stage.Stage;
47
48public class Main extends Application {
49
50 @Override
51 public void start(Stage primaryStage) throws Exception{
52 Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
53 primaryStage.setTitle("Hello World");
54 primaryStage.setScene(new Scene(root, 300, 275));
55 primaryStage.show();
56 }
57
58 public static void main(String[] args) {
59 launch(args);
60 }
61}
62public class DisplayController {
63
64 //label in display.fxml
65 @FXML
66 Label label;
67
68 public void setLabelText(String s){
69 label.setText(s);
70 }
71}
72
and in Controller.java edit enter()
function by calling a new DisplayController.java
instance:
1package sample;
2
3import javafx.fxml.FXML;
4import javafx.fxml.FXMLLoader;
5import javafx.scene.Parent;
6import javafx.scene.Scene;
7import javafx.scene.control.Label;
8import javafx.scene.control.TextField;
9import javafx.stage.Stage;
10
11import javax.xml.soap.Text;
12import java.io.IOException;
13
14public class Controller {
15
16 //textField in sample.fxml
17 @FXML
18 TextField textField;
19
20 //label in display.fxml
21 @FXML
22 Label label;
23
24 String text;
25
26 @FXML
27 public void enter() throws IOException {
28 text = textField.getText();
29
30 Stage stage = (Stage) (textField).getScene().getWindow();
31
32 Parent root = FXMLLoader.load(getClass().getResource("display.fxml"));
33 stage.setResizable(false);
34 stage.setTitle("Display");
35 stage.setScene(new Scene(root, 300, 275));
36
37 label.setText(text);
38 }
39}
40package sample;
41
42import javafx.application.Application;
43import javafx.fxml.FXMLLoader;
44import javafx.scene.Parent;
45import javafx.scene.Scene;
46import javafx.stage.Stage;
47
48public class Main extends Application {
49
50 @Override
51 public void start(Stage primaryStage) throws Exception{
52 Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
53 primaryStage.setTitle("Hello World");
54 primaryStage.setScene(new Scene(root, 300, 275));
55 primaryStage.show();
56 }
57
58 public static void main(String[] args) {
59 launch(args);
60 }
61}
62public class DisplayController {
63
64 //label in display.fxml
65 @FXML
66 Label label;
67
68 public void setLabelText(String s){
69 label.setText(s);
70 }
71}
72 @FXML
73 public void enter() throws IOException {
74 text = textField.getText();
75
76 Stage stage = (Stage) (textField).getScene().getWindow();
77 FXMLLoader loader = new FXMLLoader.load(getClass().getResource("display.fxml"));
78 Parent root = loader.load();
79 DisplayController dc = loader.getController();
80
81 //here call function to set label text
82 dc.setLabelText(text);
83
84 stage.setResizable(false);
85 stage.setTitle("Display");
86 stage.setScene(new Scene(root, 300, 275));
87
88 }
89
QUESTION
WSDL - allow different order of DataMembers for SOAP messages
Asked 2022-Feb-22 at 09:43We use ServiceStack 5.9.2.
DTO:
1 [DataContract]
2 [Restrict(Usage.SoapOnly)]
3 public class GetDocumentations : Documentations
4 {
5
6 }
7
8 [DataContract]
9 [Api("Abfrage auf von geplanten zu dokumentierenden Interventionen")]
10 public class Documentations
11 {
12 [DataMember]
13 [ApiMember(Description = "Ist dieses Feld gesetzt werden nur die Interventionen abgefragt, die sich seit dem letzten Acknowledge geändert haben.")]
14 public bool? OnlyChanged { get; set; }
15
16 [DataMember]
17 public DocumentationType Type { get; set; }
18
19 [DataMember]
20 public int[] SubTypeIds { get; set; }
21
22 [DataMember]
23 public int[] CustomerIds { get; set; }
24
25 [DataMember(IsRequired = true)]
26 public DateTime From { get; set; }
27
28 [DataMember(IsRequired = true)]
29 public DateTime To { get; set; }
30
31 [DataMember]
32 [ApiMember(Description = "Die Ergebnismenge wird auf x Elemente eingeschraenkt.")]
33 public int? Limit { get; set; }
34 }
35
resulting WSDL snipped:
1 [DataContract]
2 [Restrict(Usage.SoapOnly)]
3 public class GetDocumentations : Documentations
4 {
5
6 }
7
8 [DataContract]
9 [Api("Abfrage auf von geplanten zu dokumentierenden Interventionen")]
10 public class Documentations
11 {
12 [DataMember]
13 [ApiMember(Description = "Ist dieses Feld gesetzt werden nur die Interventionen abgefragt, die sich seit dem letzten Acknowledge geändert haben.")]
14 public bool? OnlyChanged { get; set; }
15
16 [DataMember]
17 public DocumentationType Type { get; set; }
18
19 [DataMember]
20 public int[] SubTypeIds { get; set; }
21
22 [DataMember]
23 public int[] CustomerIds { get; set; }
24
25 [DataMember(IsRequired = true)]
26 public DateTime From { get; set; }
27
28 [DataMember(IsRequired = true)]
29 public DateTime To { get; set; }
30
31 [DataMember]
32 [ApiMember(Description = "Die Ergebnismenge wird auf x Elemente eingeschraenkt.")]
33 public int? Limit { get; set; }
34 }
35 <xs:complexType name="Documentations">
36 <xs:sequence>
37 <xs:element minOccurs="0" name="CustomerIds" nillable="true" xmlns:q28="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q28:ArrayOfint" />
38 <xs:element name="From" type="xs:dateTime" />
39 <xs:element minOccurs="0" name="Limit" nillable="true" type="xs:int" />
40 <xs:element minOccurs="0" name="OnlyChanged" nillable="true" type="xs:boolean" />
41 <xs:element minOccurs="0" name="SubTypeIds" nillable="true" xmlns:q29="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q29:ArrayOfint" />
42 <xs:element name="To" type="xs:dateTime" />
43 <xs:element minOccurs="0" name="Type" type="tns:DocumentationType" />
44 </xs:sequence>
45 </xs:complexType>
46
enforces that the order in the incoming soap request is like defined:
1 [DataContract]
2 [Restrict(Usage.SoapOnly)]
3 public class GetDocumentations : Documentations
4 {
5
6 }
7
8 [DataContract]
9 [Api("Abfrage auf von geplanten zu dokumentierenden Interventionen")]
10 public class Documentations
11 {
12 [DataMember]
13 [ApiMember(Description = "Ist dieses Feld gesetzt werden nur die Interventionen abgefragt, die sich seit dem letzten Acknowledge geändert haben.")]
14 public bool? OnlyChanged { get; set; }
15
16 [DataMember]
17 public DocumentationType Type { get; set; }
18
19 [DataMember]
20 public int[] SubTypeIds { get; set; }
21
22 [DataMember]
23 public int[] CustomerIds { get; set; }
24
25 [DataMember(IsRequired = true)]
26 public DateTime From { get; set; }
27
28 [DataMember(IsRequired = true)]
29 public DateTime To { get; set; }
30
31 [DataMember]
32 [ApiMember(Description = "Die Ergebnismenge wird auf x Elemente eingeschraenkt.")]
33 public int? Limit { get; set; }
34 }
35 <xs:complexType name="Documentations">
36 <xs:sequence>
37 <xs:element minOccurs="0" name="CustomerIds" nillable="true" xmlns:q28="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q28:ArrayOfint" />
38 <xs:element name="From" type="xs:dateTime" />
39 <xs:element minOccurs="0" name="Limit" nillable="true" type="xs:int" />
40 <xs:element minOccurs="0" name="OnlyChanged" nillable="true" type="xs:boolean" />
41 <xs:element minOccurs="0" name="SubTypeIds" nillable="true" xmlns:q29="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q29:ArrayOfint" />
42 <xs:element name="To" type="xs:dateTime" />
43 <xs:element minOccurs="0" name="Type" type="tns:DocumentationType" />
44 </xs:sequence>
45 </xs:complexType>
46<?xml version="1.0" encoding="UTF-8"?>
47<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
48 <soap12:Body>
49 <GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
50 <From>2014-01-01T00:00:00</From>
51 <Limit>100</Limit>
52 <OnlyChanged>false</OnlyChanged>
53 <To>2100-01-01T00:00:00</To>
54 <Type>CarePlan</Type>
55 </GetDocumentations>
56 </soap12:Body>
57</soap12:Envelope>
58
That works, but the following not, because the Limit Property is at a different position:
1 [DataContract]
2 [Restrict(Usage.SoapOnly)]
3 public class GetDocumentations : Documentations
4 {
5
6 }
7
8 [DataContract]
9 [Api("Abfrage auf von geplanten zu dokumentierenden Interventionen")]
10 public class Documentations
11 {
12 [DataMember]
13 [ApiMember(Description = "Ist dieses Feld gesetzt werden nur die Interventionen abgefragt, die sich seit dem letzten Acknowledge geändert haben.")]
14 public bool? OnlyChanged { get; set; }
15
16 [DataMember]
17 public DocumentationType Type { get; set; }
18
19 [DataMember]
20 public int[] SubTypeIds { get; set; }
21
22 [DataMember]
23 public int[] CustomerIds { get; set; }
24
25 [DataMember(IsRequired = true)]
26 public DateTime From { get; set; }
27
28 [DataMember(IsRequired = true)]
29 public DateTime To { get; set; }
30
31 [DataMember]
32 [ApiMember(Description = "Die Ergebnismenge wird auf x Elemente eingeschraenkt.")]
33 public int? Limit { get; set; }
34 }
35 <xs:complexType name="Documentations">
36 <xs:sequence>
37 <xs:element minOccurs="0" name="CustomerIds" nillable="true" xmlns:q28="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q28:ArrayOfint" />
38 <xs:element name="From" type="xs:dateTime" />
39 <xs:element minOccurs="0" name="Limit" nillable="true" type="xs:int" />
40 <xs:element minOccurs="0" name="OnlyChanged" nillable="true" type="xs:boolean" />
41 <xs:element minOccurs="0" name="SubTypeIds" nillable="true" xmlns:q29="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q29:ArrayOfint" />
42 <xs:element name="To" type="xs:dateTime" />
43 <xs:element minOccurs="0" name="Type" type="tns:DocumentationType" />
44 </xs:sequence>
45 </xs:complexType>
46<?xml version="1.0" encoding="UTF-8"?>
47<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
48 <soap12:Body>
49 <GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
50 <From>2014-01-01T00:00:00</From>
51 <Limit>100</Limit>
52 <OnlyChanged>false</OnlyChanged>
53 <To>2100-01-01T00:00:00</To>
54 <Type>CarePlan</Type>
55 </GetDocumentations>
56 </soap12:Body>
57</soap12:Envelope>
58<?xml version="1.0" encoding="UTF-8"?>
59<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
60 <soap12:Body>
61 <GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
62 <From>2014-01-01T00:00:00</From>
63 <OnlyChanged>false</OnlyChanged>
64 <To>2100-01-01T00:00:00</To>
65 <Type>CarePlan</Type>
66 <Limit>100</Limit>
67 </GetDocumentations>
68 </soap12:Body>
69</soap12:Envelope>
70
Here the limit is ignored. Means: It is not mapped to it's property.
Change the xs:sequence to xs:all would fix that. How can we reach that? Or is there a better solution? The problem occures for many DTO's.
ANSWER
Answered 2022-Feb-22 at 09:43You can change the Order in which fields should be serialized & deserialized with the DataMember Order property, but the DataContractSerializer doesn't support accepting them being deserialized in any order.
QUESTION
unable to consume SOAP service in zeep, python
Asked 2022-Jan-31 at 05:44I was trying to consume a soap service in python with zeep. I've consumed several soap services with zeep as well. But for a particular soap service, a weird response in returning, unlike a well-organized dictionary.
My python code is below:
1import zeep
2import json
3
4def getToken1():
5wsdl2 = 'http://trx.*********ast.co.id/Webservice/b******ervice?wsdl'
6client2 = zeep.Client(wsdl2)
7parameters = {
8 'username':'n**l***s',
9 'password': 'ra8*******PeSw',
10 'counterpart':'***',
11 'ipAddress':'127.0.0.1'
12}
13info = client2.service.requestToken(parameters)
14json = zeep.helpers.serialize_object(info, dict)
15return json
16
17print(getToken1())
18
i.e. the credentials are absolutely correct.
Unfortunately the output is below:
1import zeep
2import json
3
4def getToken1():
5wsdl2 = 'http://trx.*********ast.co.id/Webservice/b******ervice?wsdl'
6client2 = zeep.Client(wsdl2)
7parameters = {
8 'username':'n**l***s',
9 'password': 'ra8*******PeSw',
10 'counterpart':'***',
11 'ipAddress':'127.0.0.1'
12}
13info = client2.service.requestToken(parameters)
14json = zeep.helpers.serialize_object(info, dict)
15return json
16
17print(getToken1())
18Traceback (most recent call last):
19File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 17, in
20<module>
21print(getToken1())
22File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 13, in
23getToken1
24info = client2.service.requestToken(parameters)
25File
26"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
27packages\zeep\proxy.py", line 46, in __call__
28return self._proxy._binding.send(
29File
30"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
31packages\zeep\wsdl\bindings\soap.py", line 135, in send
32return self.process_reply(client, operation_obj, response)
33File
34"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
35packages\zeep\wsdl\bindings\soap.py", line 206, in process_reply
36raise TransportError(
37zeep.exceptions.TransportError: Server returned response (200) with
38invalid XML: Invalid
39XML content received (AttValue: " or ' expected, line 77, column 14).
40Content: b'\n\t\t<html><head><title>NuSOAP:
41Br***stservice</title>\n\t\t<style
42type="text/css">\n\t\t body { font-family: arial; color: #000000;
43background-color:
44#ffffff; margin: 0px 0px 0px 0px; }\n\t\t p { font-family:
45arial; color:
46#000000; margin-top: 0px; margin-bottom: 12px; }\n\t\t pre {
47background-color: silver;
48padding: 5px; font-family: Courier New; font-size: x-small; color:
49#000000;}\n\t\t ul
50....................
51
It's a large response. But in soapUI :
Request:
1import zeep
2import json
3
4def getToken1():
5wsdl2 = 'http://trx.*********ast.co.id/Webservice/b******ervice?wsdl'
6client2 = zeep.Client(wsdl2)
7parameters = {
8 'username':'n**l***s',
9 'password': 'ra8*******PeSw',
10 'counterpart':'***',
11 'ipAddress':'127.0.0.1'
12}
13info = client2.service.requestToken(parameters)
14json = zeep.helpers.serialize_object(info, dict)
15return json
16
17print(getToken1())
18Traceback (most recent call last):
19File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 17, in
20<module>
21print(getToken1())
22File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 13, in
23getToken1
24info = client2.service.requestToken(parameters)
25File
26"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
27packages\zeep\proxy.py", line 46, in __call__
28return self._proxy._binding.send(
29File
30"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
31packages\zeep\wsdl\bindings\soap.py", line 135, in send
32return self.process_reply(client, operation_obj, response)
33File
34"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
35packages\zeep\wsdl\bindings\soap.py", line 206, in process_reply
36raise TransportError(
37zeep.exceptions.TransportError: Server returned response (200) with
38invalid XML: Invalid
39XML content received (AttValue: " or ' expected, line 77, column 14).
40Content: b'\n\t\t<html><head><title>NuSOAP:
41Br***stservice</title>\n\t\t<style
42type="text/css">\n\t\t body { font-family: arial; color: #000000;
43background-color:
44#ffffff; margin: 0px 0px 0px 0px; }\n\t\t p { font-family:
45arial; color:
46#000000; margin-top: 0px; margin-bottom: 12px; }\n\t\t pre {
47background-color: silver;
48padding: 5px; font-family: Courier New; font-size: x-small; color:
49#000000;}\n\t\t ul
50....................
51<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
52xmlns:xsd="http://www.w3.org/2001/XMLSchema"
53xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
54xmlns:urn="urn:SOAPServerWSDL">
55<soapenv:Header/>
56 <soapenv:Body>
57 <urn:requestToken
58 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
59 <parameters xsi:type="urn:requestTokenCT"
60 xmlns:urn="urn:***stservice">
61 <!--You may enter the following 4 items in any order-->
62 <username xsi:type="xsd:string">nbl**s</username>
63 <password xsi:type="xsd:string">ra8*******4iphEsPeSw</password>
64 <counterpart xsi:type="xsd:string">N*L</counterpart>
65 <ipAddress xsi:type="xsd:string">127.0.0.1</ipAddress>
66 </parameters>
67 </urn:requestToken>
68 </soapenv:Body>
69</soapenv:Envelope>
70
Response:
1import zeep
2import json
3
4def getToken1():
5wsdl2 = 'http://trx.*********ast.co.id/Webservice/b******ervice?wsdl'
6client2 = zeep.Client(wsdl2)
7parameters = {
8 'username':'n**l***s',
9 'password': 'ra8*******PeSw',
10 'counterpart':'***',
11 'ipAddress':'127.0.0.1'
12}
13info = client2.service.requestToken(parameters)
14json = zeep.helpers.serialize_object(info, dict)
15return json
16
17print(getToken1())
18Traceback (most recent call last):
19File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 17, in
20<module>
21print(getToken1())
22File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 13, in
23getToken1
24info = client2.service.requestToken(parameters)
25File
26"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
27packages\zeep\proxy.py", line 46, in __call__
28return self._proxy._binding.send(
29File
30"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
31packages\zeep\wsdl\bindings\soap.py", line 135, in send
32return self.process_reply(client, operation_obj, response)
33File
34"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-
35packages\zeep\wsdl\bindings\soap.py", line 206, in process_reply
36raise TransportError(
37zeep.exceptions.TransportError: Server returned response (200) with
38invalid XML: Invalid
39XML content received (AttValue: " or ' expected, line 77, column 14).
40Content: b'\n\t\t<html><head><title>NuSOAP:
41Br***stservice</title>\n\t\t<style
42type="text/css">\n\t\t body { font-family: arial; color: #000000;
43background-color:
44#ffffff; margin: 0px 0px 0px 0px; }\n\t\t p { font-family:
45arial; color:
46#000000; margin-top: 0px; margin-bottom: 12px; }\n\t\t pre {
47background-color: silver;
48padding: 5px; font-family: Courier New; font-size: x-small; color:
49#000000;}\n\t\t ul
50....................
51<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
52xmlns:xsd="http://www.w3.org/2001/XMLSchema"
53xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
54xmlns:urn="urn:SOAPServerWSDL">
55<soapenv:Header/>
56 <soapenv:Body>
57 <urn:requestToken
58 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
59 <parameters xsi:type="urn:requestTokenCT"
60 xmlns:urn="urn:***stservice">
61 <!--You may enter the following 4 items in any order-->
62 <username xsi:type="xsd:string">nbl**s</username>
63 <password xsi:type="xsd:string">ra8*******4iphEsPeSw</password>
64 <counterpart xsi:type="xsd:string">N*L</counterpart>
65 <ipAddress xsi:type="xsd:string">127.0.0.1</ipAddress>
66 </parameters>
67 </urn:requestToken>
68 </soapenv:Body>
69</soapenv:Envelope>
70<SOAP-ENV:Envelope SOAP-
71ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
72xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
73xmlns:xsd="http://www.w3.org/2001/XMLSchema"
74xmlns:xsi="http://www.w3.org/2001/XMLSchema-
75instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
76xmlns:tns="urn:Brifastservice">
77 <SOAP-ENV:Body>
78 <ns1:requestTokenResponse xmlns:ns1="urn:SOAPServerWSDL">
79 <return xsi:type="tns:requestTokenCTResult">
80 <message xsi:type="xsd:string">Success</message>
81 <statusCode xsi:type="xsd:string">0**01</statusCode>
82 <token
83 xsi:type="xsd:string">99B4631DCD445***23BF6CED31C1B6574</token>
84 </return>
85 </ns1:requestTokenResponse>
86 </SOAP-ENV:Body>
87</SOAP-ENV:Envelope>
88
Can anyone help me to get data from this soap service through zeep in python?
ANSWER
Answered 2022-Jan-31 at 05:44Your requested WSDL URL contains https protocol and you are calling http request.
Please call this url : https://trx.*********ast.co.id/Webservice/b******ervice?wsdl
QUESTION
how to edit the response fields in node-soap
Asked 2021-Dec-25 at 07:07I have the following WSDL definition:
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40
and the following handler definition:
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55
Currently, when receiving the following request:
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
56 <soapenv:Body>
57 <app:SoapQuery xmlns:app="http://app.com/app">
58 <TransType>11124</TransType>
59 </app:SoapQuery>
60 </soapenv:Body>
61</soapenv:Envelope>
62
it returns:
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
56 <soapenv:Body>
57 <app:SoapQuery xmlns:app="http://app.com/app">
58 <TransType>11124</TransType>
59 </app:SoapQuery>
60 </soapenv:Body>
61</soapenv:Envelope>
62<?xml version="1.0" encoding="utf-8"?>
63<soap:Envelope
64 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
65 xmlns:app="http://app.com/app">
66 <soap:Body>
67 <app:SoapQueryResponse>
68 <app:ResultCode>0</app:ResultCode>
69 <app:ResultDesc>sdfds</app:ResultDesc>
70 </app:SoapQueryResponse>
71 </soap:Body>
72</soap:Envelope>
73
But I want the response to look like:
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
56 <soapenv:Body>
57 <app:SoapQuery xmlns:app="http://app.com/app">
58 <TransType>11124</TransType>
59 </app:SoapQuery>
60 </soapenv:Body>
61</soapenv:Envelope>
62<?xml version="1.0" encoding="utf-8"?>
63<soap:Envelope
64 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
65 xmlns:app="http://app.com/app">
66 <soap:Body>
67 <app:SoapQueryResponse>
68 <app:ResultCode>0</app:ResultCode>
69 <app:ResultDesc>sdfds</app:ResultDesc>
70 </app:SoapQueryResponse>
71 </soap:Body>
72</soap:Envelope>
73<?xml version="1.0" encoding="utf-8"?>
74<soap:Envelope
75 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
76 xmlns:app="http://app.com/app">
77 <soap:Body>
78 <app:SoapQueryResult> <!-- not - SoapQueryResponse -->
79 <ResultCode>0</ResultCode> <!-- notice there is no `app:` -->
80 <ResultDesc>sdfds</ResultDesc> <!-- notice there is no `app:` -->
81 </app:SoapQueryResult>
82 </soap:Body>
83</soap:Envelope>
84
I have tried different approaches but none to seem to have effect on the response type. I feel like I am missing something in the WSDL or the handler..
ANSWER
Answered 2021-Dec-25 at 07:07Omit the RPC
tag in your WSDL definition and change it from
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
to
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
because you're using RPC
as style it's adding app:
to the output message and the parts, ignoring your outputName
and replacing it with SoapQueryResponse
as well. Removing the RPC
tag will give you this output
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
56 <soapenv:Body>
57 <app:SoapQuery xmlns:app="http://app.com/app">
58 <TransType>11124</TransType>
59 </app:SoapQuery>
60 </soapenv:Body>
61</soapenv:Envelope>
62<?xml version="1.0" encoding="utf-8"?>
63<soap:Envelope
64 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
65 xmlns:app="http://app.com/app">
66 <soap:Body>
67 <app:SoapQueryResponse>
68 <app:ResultCode>0</app:ResultCode>
69 <app:ResultDesc>sdfds</app:ResultDesc>
70 </app:SoapQueryResponse>
71 </soap:Body>
72</soap:Envelope>
73<?xml version="1.0" encoding="utf-8"?>
74<soap:Envelope
75 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
76 xmlns:app="http://app.com/app">
77 <soap:Body>
78 <app:SoapQueryResult> <!-- not - SoapQueryResponse -->
79 <ResultCode>0</ResultCode> <!-- notice there is no `app:` -->
80 <ResultDesc>sdfds</ResultDesc> <!-- notice there is no `app:` -->
81 </app:SoapQueryResult>
82 </soap:Body>
83</soap:Envelope>
84<?xml version="1.0" encoding="utf-8"?>
85<soap:Envelope
86 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
87 xmlns:app="http://app.com/app">
88 <soap:Body>
89 <SoapQueryResult> <!-- notice there is no `app:` -->
90 <ResultCode>0</ResultCode>
91 <ResultDesc>sdfds</ResultDesc>
92 </SoapQueryResult>
93 </soap:Body>
94</soap:Envelope>
95
By default node-soap
will remove all targetNamespace
prefix from the message and message parts if is not stylized RPC
. I have created a pull request here which will allow users to add optional targetNamespace
on the output message to be prefixed on the output only not the parts. So with the suggested pull request, you'd add targetNamespace
to your message
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
56 <soapenv:Body>
57 <app:SoapQuery xmlns:app="http://app.com/app">
58 <TransType>11124</TransType>
59 </app:SoapQuery>
60 </soapenv:Body>
61</soapenv:Envelope>
62<?xml version="1.0" encoding="utf-8"?>
63<soap:Envelope
64 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
65 xmlns:app="http://app.com/app">
66 <soap:Body>
67 <app:SoapQueryResponse>
68 <app:ResultCode>0</app:ResultCode>
69 <app:ResultDesc>sdfds</app:ResultDesc>
70 </app:SoapQueryResponse>
71 </soap:Body>
72</soap:Envelope>
73<?xml version="1.0" encoding="utf-8"?>
74<soap:Envelope
75 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
76 xmlns:app="http://app.com/app">
77 <soap:Body>
78 <app:SoapQueryResult> <!-- not - SoapQueryResponse -->
79 <ResultCode>0</ResultCode> <!-- notice there is no `app:` -->
80 <ResultDesc>sdfds</ResultDesc> <!-- notice there is no `app:` -->
81 </app:SoapQueryResult>
82 </soap:Body>
83</soap:Envelope>
84<?xml version="1.0" encoding="utf-8"?>
85<soap:Envelope
86 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
87 xmlns:app="http://app.com/app">
88 <soap:Body>
89 <SoapQueryResult> <!-- notice there is no `app:` -->
90 <ResultCode>0</ResultCode>
91 <ResultDesc>sdfds</ResultDesc>
92 </SoapQueryResult>
93 </soap:Body>
94</soap:Envelope>
95 <message name="SoapQueryResult" targetNamespace="app">
96 <part name="ResponseCode" type="xsd:string"/>
97 <part name="ResultDesc" type="xsd:string" />
98 </message>
99
and you'll get your desired output
1<definitions targetNamespace="http://app.com/app" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:app="http://app.com/app" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
3 <message name="SoapQuery">
4 <part name="TransType" type="xsd:string" />
5 </message>
6
7 <message name="SoapQueryResult">
8 <part name="ResponseCode" type="xsd:string"/>
9 <part name="ResultDesc" type="xsd:string" />
10 </message>
11
12 <portType name="SoapQuery_PortType">
13 <operation name="SoapQuery">
14 <input message="SoapQuery" />
15 <output message="SoapQueryResult" />
16 </operation>
17 </portType>
18
19 <binding name="SoapQuery_Binding" type="SoapQuery_PortType">
20 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
21 <operation name="SoapQuery" style="document">
22 <soap:operation soapAction="SoapQuery" />
23 <soap:input>
24 <soap:body namespace="app" use="literal" />
25 </soap:input>
26
27 <soap:output>
28 <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal" />
29 </soap:output>
30 </operation>
31 </binding>
32
33 <service name="SoapQueryService">
34 <documentation>WSDL File for SoapQueryService</documentation>
35 <port binding="SoapQuery_Binding" name="SoapQuery_Port">
36 <soap:address location="http://localhost:8002/api/request" />
37 </port>
38 </service>
39</definitions>
40var SoapQueryService = {
41 SoapQueryService: {
42 SoapQuery_Port: {
43 // This is how to define an asynchronous function.
44 SoapQuery: function (args, callback) {
45 // do some work
46 callback({
47 'ResultCode': 0,
48 'ResultDesc': "sdfds",
49 });
50 }
51 }
52 }
53};
54
55<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
56 <soapenv:Body>
57 <app:SoapQuery xmlns:app="http://app.com/app">
58 <TransType>11124</TransType>
59 </app:SoapQuery>
60 </soapenv:Body>
61</soapenv:Envelope>
62<?xml version="1.0" encoding="utf-8"?>
63<soap:Envelope
64 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
65 xmlns:app="http://app.com/app">
66 <soap:Body>
67 <app:SoapQueryResponse>
68 <app:ResultCode>0</app:ResultCode>
69 <app:ResultDesc>sdfds</app:ResultDesc>
70 </app:SoapQueryResponse>
71 </soap:Body>
72</soap:Envelope>
73<?xml version="1.0" encoding="utf-8"?>
74<soap:Envelope
75 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
76 xmlns:app="http://app.com/app">
77 <soap:Body>
78 <app:SoapQueryResult> <!-- not - SoapQueryResponse -->
79 <ResultCode>0</ResultCode> <!-- notice there is no `app:` -->
80 <ResultDesc>sdfds</ResultDesc> <!-- notice there is no `app:` -->
81 </app:SoapQueryResult>
82 </soap:Body>
83</soap:Envelope>
84<?xml version="1.0" encoding="utf-8"?>
85<soap:Envelope
86 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
87 xmlns:app="http://app.com/app">
88 <soap:Body>
89 <SoapQueryResult> <!-- notice there is no `app:` -->
90 <ResultCode>0</ResultCode>
91 <ResultDesc>sdfds</ResultDesc>
92 </SoapQueryResult>
93 </soap:Body>
94</soap:Envelope>
95 <message name="SoapQueryResult" targetNamespace="app">
96 <part name="ResponseCode" type="xsd:string"/>
97 <part name="ResultDesc" type="xsd:string" />
98 </message>
99<?xml version="1.0" encoding="utf-8"?>
100<soap:Envelope
101 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
102 xmlns:app="http://app.com/app">
103 <soap:Body>
104 <app:SoapQueryResult>
105 <ResultCode>0</ResultCode>
106 <ResultDesc>sdfds</ResultDesc>
107 </app:SoapQueryResult>
108 </soap:Body>
109</soap:Envelope>
110
QUESTION
Anypoint Studio problem with JSON into XML transformation
Asked 2021-Dec-20 at 21:26I am trying to convert JSON response into XML and then call SOAP API with payload. I managed to get JSON response without any trouble, but I am unable to convert it to XML. the problem is data has to be in format:
1<?xml version="1.0" encoding="utf-8"?>
2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3 <soap:Body>
4 <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
5 <dNum>47.92</dNum>
6 </NumberToDollars>
7 </soap:Body>
8</soap:Envelope>
9
but when I use this as example for Transform Messages
module it creates:
1<?xml version="1.0" encoding="utf-8"?>
2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3 <soap:Body>
4 <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
5 <dNum>47.92</dNum>
6 </NumberToDollars>
7 </soap:Body>
8</soap:Envelope>
9%dw 2.0
10output application/xml
11ns ns00 http://schemas.xmlsoap.org/soap/envelope/
12ns ns01 http://www.dataaccess.com/webservicesserver/
13---
14{
15 ns00#Envelope: {
16 ns00#Body: {
17 ns01#NumberToDollars: {
18 ns01#dNum: payload.decimal
19 }
20 }
21 }
22}
23
and when I use a Logger
to view the output it is:
1<?xml version="1.0" encoding="utf-8"?>
2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3 <soap:Body>
4 <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
5 <dNum>47.92</dNum>
6 </NumberToDollars>
7 </soap:Body>
8</soap:Envelope>
9%dw 2.0
10output application/xml
11ns ns00 http://schemas.xmlsoap.org/soap/envelope/
12ns ns01 http://www.dataaccess.com/webservicesserver/
13---
14{
15 ns00#Envelope: {
16 ns00#Body: {
17 ns01#NumberToDollars: {
18 ns01#dNum: payload.decimal
19 }
20 }
21 }
22}
23<?xml version='1.0' encoding='UTF-8'?>
24<ns00:Envelope xmlns:ns00="http://schemas.xmlsoap.org/soap/envelope/">
25 <ns00:Body>
26 <ns01:NumberToDollars xmlns:ns01="http://www.dataaccess.com/webservicesserver/">
27 <ns01:dNum>47.92</ns01:dNum>
28 </ns01:NumberToDollars>
29 </ns00:Body>
30</ns00:Envelope>
31
I know I can change it manually and I managed to get it to look like this:
1<?xml version="1.0" encoding="utf-8"?>
2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3 <soap:Body>
4 <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
5 <dNum>47.92</dNum>
6 </NumberToDollars>
7 </soap:Body>
8</soap:Envelope>
9%dw 2.0
10output application/xml
11ns ns00 http://schemas.xmlsoap.org/soap/envelope/
12ns ns01 http://www.dataaccess.com/webservicesserver/
13---
14{
15 ns00#Envelope: {
16 ns00#Body: {
17 ns01#NumberToDollars: {
18 ns01#dNum: payload.decimal
19 }
20 }
21 }
22}
23<?xml version='1.0' encoding='UTF-8'?>
24<ns00:Envelope xmlns:ns00="http://schemas.xmlsoap.org/soap/envelope/">
25 <ns00:Body>
26 <ns01:NumberToDollars xmlns:ns01="http://www.dataaccess.com/webservicesserver/">
27 <ns01:dNum>47.92</ns01:dNum>
28 </ns01:NumberToDollars>
29 </ns00:Body>
30</ns00:Envelope>
31%dw 2.0
32output application/xml
33ns soap http://schemas.xmlsoap.org/soap/envelope/
34ns ns01 http://www.dataaccess.com/webservicesserver/
35---
36{
37 soap#Envelope: {
38 soap#Body: {
39 NumberToDollars: {
40 dNum: payload.decimal
41 }
42 }
43 }
44}
45
output:
1<?xml version="1.0" encoding="utf-8"?>
2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3 <soap:Body>
4 <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
5 <dNum>47.92</dNum>
6 </NumberToDollars>
7 </soap:Body>
8</soap:Envelope>
9%dw 2.0
10output application/xml
11ns ns00 http://schemas.xmlsoap.org/soap/envelope/
12ns ns01 http://www.dataaccess.com/webservicesserver/
13---
14{
15 ns00#Envelope: {
16 ns00#Body: {
17 ns01#NumberToDollars: {
18 ns01#dNum: payload.decimal
19 }
20 }
21 }
22}
23<?xml version='1.0' encoding='UTF-8'?>
24<ns00:Envelope xmlns:ns00="http://schemas.xmlsoap.org/soap/envelope/">
25 <ns00:Body>
26 <ns01:NumberToDollars xmlns:ns01="http://www.dataaccess.com/webservicesserver/">
27 <ns01:dNum>47.92</ns01:dNum>
28 </ns01:NumberToDollars>
29 </ns00:Body>
30</ns00:Envelope>
31%dw 2.0
32output application/xml
33ns soap http://schemas.xmlsoap.org/soap/envelope/
34ns ns01 http://www.dataaccess.com/webservicesserver/
35---
36{
37 soap#Envelope: {
38 soap#Body: {
39 NumberToDollars: {
40 dNum: payload.decimal
41 }
42 }
43 }
44}
45<?xml version='1.0' encoding='UTF-8'?>
46<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
47 <soap:Body>
48 <NumberToDollars>
49 <dNum>47.92</dNum>
50 </NumberToDollars>
51 </soap:Body>
52</soap:Envelope>
53
But I have no idea how to get NumberToDollarsbe without namespace and at the same time to have xmlns link (how can I get rid of ns00 and at the same time keeping the link).
I checked all there was about it in Mule Documentation and found nothing please, please help.
ANSWER
Answered 2021-Dec-20 at 21:26A way to do that is to define xmlns
as if it were a normal attribute:
1<?xml version="1.0" encoding="utf-8"?>
2<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
3 <soap:Body>
4 <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
5 <dNum>47.92</dNum>
6 </NumberToDollars>
7 </soap:Body>
8</soap:Envelope>
9%dw 2.0
10output application/xml
11ns ns00 http://schemas.xmlsoap.org/soap/envelope/
12ns ns01 http://www.dataaccess.com/webservicesserver/
13---
14{
15 ns00#Envelope: {
16 ns00#Body: {
17 ns01#NumberToDollars: {
18 ns01#dNum: payload.decimal
19 }
20 }
21 }
22}
23<?xml version='1.0' encoding='UTF-8'?>
24<ns00:Envelope xmlns:ns00="http://schemas.xmlsoap.org/soap/envelope/">
25 <ns00:Body>
26 <ns01:NumberToDollars xmlns:ns01="http://www.dataaccess.com/webservicesserver/">
27 <ns01:dNum>47.92</ns01:dNum>
28 </ns01:NumberToDollars>
29 </ns00:Body>
30</ns00:Envelope>
31%dw 2.0
32output application/xml
33ns soap http://schemas.xmlsoap.org/soap/envelope/
34ns ns01 http://www.dataaccess.com/webservicesserver/
35---
36{
37 soap#Envelope: {
38 soap#Body: {
39 NumberToDollars: {
40 dNum: payload.decimal
41 }
42 }
43 }
44}
45<?xml version='1.0' encoding='UTF-8'?>
46<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
47 <soap:Body>
48 <NumberToDollars>
49 <dNum>47.92</dNum>
50 </NumberToDollars>
51 </soap:Body>
52</soap:Envelope>
53%dw 2.0
54output application/xml
55ns ns00 http://schemas.xmlsoap.org/soap/envelope/
56ns ns01 http://www.dataaccess.com/webservicesserver/
57---
58{
59 ns00#Envelope: {
60 ns00#Body: {
61 NumberToDollars @(xmlns: "http://www.dataaccess.com/webservicesserver/"): {
62 dNum: payload.decimal
63 }
64 }
65 }
66}
67
QUESTION
Estes Express Api Version 4.0 Rate Quote
Asked 2021-Dec-16 at 17:19I am trying to test Estes Express Freight API and have ran into a problem. I have the request object set up (and get expected error response back) except for the commodity part. There wsdl does not include a direct match such as commodity, basecommodity, or full commodities in their request class but just give an item as object type.
1 ```
2
3
4
5 [System.Xml.Serialization.XmlElementAttribute("baseCommodities",
6 typeof(BaseCommoditiesType))]
7 [System.Xml.Serialization.XmlElementAttribute("fullCommodities",
8 typeof(FullCommoditiesType))]
9 public object Item {
10 get {
11 return this.itemField;
12 }
13 set {
14 this.itemField = value;
15 }
16 }
17
18[System.Xml.Serialization.XmlElement("commodity", typeof(FullCommodityType))]//added to request class recently
19
20 public object Items
21 {
22 get
23 {
24 return this.itemsField;
25 }
26 set
27 {
28 this.itemsField = value;
29 }
30 }
31
32
33```
34
Here is my code so far. I have tried several things which only wind up being xml document not made. I do not understand how to add commodity, and full commodity items to the request object. Now with the hack, all I need to do is wrap the "fullCommodities" element around the "commodity" element. That is my only question now.
1 ```
2
3
4
5 [System.Xml.Serialization.XmlElementAttribute("baseCommodities",
6 typeof(BaseCommoditiesType))]
7 [System.Xml.Serialization.XmlElementAttribute("fullCommodities",
8 typeof(FullCommoditiesType))]
9 public object Item {
10 get {
11 return this.itemField;
12 }
13 set {
14 this.itemField = value;
15 }
16 }
17
18[System.Xml.Serialization.XmlElement("commodity", typeof(FullCommodityType))]//added to request class recently
19
20 public object Items
21 {
22 get
23 {
24 return this.itemsField;
25 }
26 set
27 {
28 this.itemsField = value;
29 }
30 }
31
32
33```
34
35
36static void Main(string[] args)
37 {
38 RateQuoteService service = new RateQuoteService() ;
39
40 AuthenticationType authentication = new AuthenticationType();
41 authentication.user = "xxxxxxxx";
42 authentication.password = "xxxxxx";
43 service.auth = authentication;
44
45 rateRequest request = new rateRequest();
46 rateQuote quote = new rateQuote();
47
48 request.requestID = generateID();//just guid value for now
49
50 request.account = "xxxxxxx";
51
52 PointType origin = new PointType();
53 origin.city = "Shelby TownShip";
54 origin.postalCode = "48315";
55 origin.stateProvince = "MI";
56 origin.countryCode = "US";
57 request.originPoint = origin;
58
59 PointType destination = new PointType();
60 destination.city = "Fenton";
61 destination.postalCode = "48430";
62 destination.stateProvince = "MI";
63 destination.countryCode = "US";
64 request.destinationPoint = destination;
65
66 request.payor = "S";
67 request.terms = "P";
68
69 PickupType pickUP = new PickupType();
70 request.pickup = pickUP;
71 request.declaredValue = 1000.00M;
72 request.declaredValueSpecified = true;
73
74 request.stackable = YesNoBlankType.N;//enum
75 request.stackableSpecified = true;
76 request.linearFeet = "80";
77 request.foodWarehouse = "other";
78
79 request.declaredValueWaived = YesNoBlankType.N;//enum
80 request.declaredValueWaivedSpecified = true;
81
82 FullCommoditiesType fcom = new FullCommoditiesType();//just commodity property
83 FullCommodityType fcomtypes = new FullCommodityType();//all other properties
84
85 DimensionsType dim = new DimensionsType();
86 dim.length = "75";
87 dim.width = "50";
88 dim.height = "25";
89
90 fcomtypes.@class = 70.0M;
91 fcomtypes.weight = "500";
92 fcomtypes.pieces = "2";
93 fcomtypes.pieceType = PackagingType.PT;
94 fcomtypes.classSpecified = true;
95 fcomtypes.dimensions = dim;
96
97 //fcom.commodity = ????
98 //request.Item = ????//I'm assuming fcomtypes but dosent work
99
100request.Items = fcomtypes; //Hack - Now this adds what I need to the request object
101
102 //request.Item = fcomtypes as FullCommodityType;//dont work either
103
104 quote = service.getQuote(request);
105
106
107
108
109
110
111
112
113
114
115 }
116
117
XML generated:
1 ```
2
3
4
5 [System.Xml.Serialization.XmlElementAttribute("baseCommodities",
6 typeof(BaseCommoditiesType))]
7 [System.Xml.Serialization.XmlElementAttribute("fullCommodities",
8 typeof(FullCommoditiesType))]
9 public object Item {
10 get {
11 return this.itemField;
12 }
13 set {
14 this.itemField = value;
15 }
16 }
17
18[System.Xml.Serialization.XmlElement("commodity", typeof(FullCommodityType))]//added to request class recently
19
20 public object Items
21 {
22 get
23 {
24 return this.itemsField;
25 }
26 set
27 {
28 this.itemsField = value;
29 }
30 }
31
32
33```
34
35
36static void Main(string[] args)
37 {
38 RateQuoteService service = new RateQuoteService() ;
39
40 AuthenticationType authentication = new AuthenticationType();
41 authentication.user = "xxxxxxxx";
42 authentication.password = "xxxxxx";
43 service.auth = authentication;
44
45 rateRequest request = new rateRequest();
46 rateQuote quote = new rateQuote();
47
48 request.requestID = generateID();//just guid value for now
49
50 request.account = "xxxxxxx";
51
52 PointType origin = new PointType();
53 origin.city = "Shelby TownShip";
54 origin.postalCode = "48315";
55 origin.stateProvince = "MI";
56 origin.countryCode = "US";
57 request.originPoint = origin;
58
59 PointType destination = new PointType();
60 destination.city = "Fenton";
61 destination.postalCode = "48430";
62 destination.stateProvince = "MI";
63 destination.countryCode = "US";
64 request.destinationPoint = destination;
65
66 request.payor = "S";
67 request.terms = "P";
68
69 PickupType pickUP = new PickupType();
70 request.pickup = pickUP;
71 request.declaredValue = 1000.00M;
72 request.declaredValueSpecified = true;
73
74 request.stackable = YesNoBlankType.N;//enum
75 request.stackableSpecified = true;
76 request.linearFeet = "80";
77 request.foodWarehouse = "other";
78
79 request.declaredValueWaived = YesNoBlankType.N;//enum
80 request.declaredValueWaivedSpecified = true;
81
82 FullCommoditiesType fcom = new FullCommoditiesType();//just commodity property
83 FullCommodityType fcomtypes = new FullCommodityType();//all other properties
84
85 DimensionsType dim = new DimensionsType();
86 dim.length = "75";
87 dim.width = "50";
88 dim.height = "25";
89
90 fcomtypes.@class = 70.0M;
91 fcomtypes.weight = "500";
92 fcomtypes.pieces = "2";
93 fcomtypes.pieceType = PackagingType.PT;
94 fcomtypes.classSpecified = true;
95 fcomtypes.dimensions = dim;
96
97 //fcom.commodity = ????
98 //request.Item = ????//I'm assuming fcomtypes but dosent work
99
100request.Items = fcomtypes; //Hack - Now this adds what I need to the request object
101
102 //request.Item = fcomtypes as FullCommodityType;//dont work either
103
104 quote = service.getQuote(request);
105
106
107
108
109
110
111
112
113
114
115 }
116
117 <?xml version="1.0" encoding="utf-8"?>
118<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
119 <soap:Header>
120 <auth xmlns="http://ws.estesexpress.com/ratequote">
121 <user>xxxxxx</user>
122 <password>xxxxxxxx</password>
123 </auth>
124 </soap:Header>
125 <soap:Body>
126 <rateRequest xmlns="http://ws.estesexpress.com/schema/2019/01/ratequote">
127 <requestID>5fdbdbeedf474a439a54559750c2c5ea</requestID>
128 <account>xxxxxxx</account>
129 <originPoint>
130 <countryCode>US</countryCode>
131 <postalCode>48315</postalCode>
132 <city>Shelby TownShip</city>
133 <stateProvince>MI</stateProvince>
134 </originPoint>
135 <destinationPoint>
136 <countryCode>US</countryCode>
137 <postalCode>48430</postalCode>
138 <city>Fenton</city>
139 <stateProvince>MI</stateProvince>
140 </destinationPoint>
141 <payor>S</payor>
142 <terms>P</terms>
143 <pickup>
144 <date>0001-01-01</date>
145 </pickup>
146 <declaredValue>1000.00</declaredValue>
147 <declaredValueWaived>N</declaredValueWaived>
148 <stackable>N</stackable>
149 <linearFeet>80</linearFeet>
150 <foodWarehouse>other</foodWarehouse>
151 <commodity>
152 <class>70.0</class>
153 <weight>500</weight>
154 <pieces>2</pieces>
155 <pieceType>PT</pieceType>
156 <dimensions>
157 <length>75</length>
158 <width>50</width>
159 <height>25</height>
160 </dimensions>
161 <description>test</description>
162 </commodity>
163 </rateRequest>
164 </soap:Body>
165</soap:Envelope>
166
Expected Fault Back:
1 ```
2
3
4
5 [System.Xml.Serialization.XmlElementAttribute("baseCommodities",
6 typeof(BaseCommoditiesType))]
7 [System.Xml.Serialization.XmlElementAttribute("fullCommodities",
8 typeof(FullCommoditiesType))]
9 public object Item {
10 get {
11 return this.itemField;
12 }
13 set {
14 this.itemField = value;
15 }
16 }
17
18[System.Xml.Serialization.XmlElement("commodity", typeof(FullCommodityType))]//added to request class recently
19
20 public object Items
21 {
22 get
23 {
24 return this.itemsField;
25 }
26 set
27 {
28 this.itemsField = value;
29 }
30 }
31
32
33```
34
35
36static void Main(string[] args)
37 {
38 RateQuoteService service = new RateQuoteService() ;
39
40 AuthenticationType authentication = new AuthenticationType();
41 authentication.user = "xxxxxxxx";
42 authentication.password = "xxxxxx";
43 service.auth = authentication;
44
45 rateRequest request = new rateRequest();
46 rateQuote quote = new rateQuote();
47
48 request.requestID = generateID();//just guid value for now
49
50 request.account = "xxxxxxx";
51
52 PointType origin = new PointType();
53 origin.city = "Shelby TownShip";
54 origin.postalCode = "48315";
55 origin.stateProvince = "MI";
56 origin.countryCode = "US";
57 request.originPoint = origin;
58
59 PointType destination = new PointType();
60 destination.city = "Fenton";
61 destination.postalCode = "48430";
62 destination.stateProvince = "MI";
63 destination.countryCode = "US";
64 request.destinationPoint = destination;
65
66 request.payor = "S";
67 request.terms = "P";
68
69 PickupType pickUP = new PickupType();
70 request.pickup = pickUP;
71 request.declaredValue = 1000.00M;
72 request.declaredValueSpecified = true;
73
74 request.stackable = YesNoBlankType.N;//enum
75 request.stackableSpecified = true;
76 request.linearFeet = "80";
77 request.foodWarehouse = "other";
78
79 request.declaredValueWaived = YesNoBlankType.N;//enum
80 request.declaredValueWaivedSpecified = true;
81
82 FullCommoditiesType fcom = new FullCommoditiesType();//just commodity property
83 FullCommodityType fcomtypes = new FullCommodityType();//all other properties
84
85 DimensionsType dim = new DimensionsType();
86 dim.length = "75";
87 dim.width = "50";
88 dim.height = "25";
89
90 fcomtypes.@class = 70.0M;
91 fcomtypes.weight = "500";
92 fcomtypes.pieces = "2";
93 fcomtypes.pieceType = PackagingType.PT;
94 fcomtypes.classSpecified = true;
95 fcomtypes.dimensions = dim;
96
97 //fcom.commodity = ????
98 //request.Item = ????//I'm assuming fcomtypes but dosent work
99
100request.Items = fcomtypes; //Hack - Now this adds what I need to the request object
101
102 //request.Item = fcomtypes as FullCommodityType;//dont work either
103
104 quote = service.getQuote(request);
105
106
107
108
109
110
111
112
113
114
115 }
116
117 <?xml version="1.0" encoding="utf-8"?>
118<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
119 <soap:Header>
120 <auth xmlns="http://ws.estesexpress.com/ratequote">
121 <user>xxxxxx</user>
122 <password>xxxxxxxx</password>
123 </auth>
124 </soap:Header>
125 <soap:Body>
126 <rateRequest xmlns="http://ws.estesexpress.com/schema/2019/01/ratequote">
127 <requestID>5fdbdbeedf474a439a54559750c2c5ea</requestID>
128 <account>xxxxxxx</account>
129 <originPoint>
130 <countryCode>US</countryCode>
131 <postalCode>48315</postalCode>
132 <city>Shelby TownShip</city>
133 <stateProvince>MI</stateProvince>
134 </originPoint>
135 <destinationPoint>
136 <countryCode>US</countryCode>
137 <postalCode>48430</postalCode>
138 <city>Fenton</city>
139 <stateProvince>MI</stateProvince>
140 </destinationPoint>
141 <payor>S</payor>
142 <terms>P</terms>
143 <pickup>
144 <date>0001-01-01</date>
145 </pickup>
146 <declaredValue>1000.00</declaredValue>
147 <declaredValueWaived>N</declaredValueWaived>
148 <stackable>N</stackable>
149 <linearFeet>80</linearFeet>
150 <foodWarehouse>other</foodWarehouse>
151 <commodity>
152 <class>70.0</class>
153 <weight>500</weight>
154 <pieces>2</pieces>
155 <pieceType>PT</pieceType>
156 <dimensions>
157 <length>75</length>
158 <width>50</width>
159 <height>25</height>
160 </dimensions>
161 <description>test</description>
162 </commodity>
163 </rateRequest>
164 </soap:Body>
165</soap:Envelope>
166 <?xml version='1.0' encoding='utf-8'?>
167<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
168 <soapenv:Header/>
169 <soapenv:Body>
170 <soapenv:Fault>
171 <faultcode>soapenv:Server</faultcode>
172 <faultstring>Schema validation error</faultstring>
173 <detail>
174 <rat:schemaError xmlns:rat="http://ws.estesexpress.com/ratequote">
175 <rat:error>Expected elements 'baseCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote fullCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote' before the end of the content in element rateRequest@http://ws.estesexpress.com/schema/2019/01/ratequote</rat:error>
176 <rat:error>Expected elements 'baseCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote fullCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote' instead of 'commodity@http://ws.estesexpress.com/schema/2019/01/ratequote' here in element rateRequest@http://ws.estesexpress.com/schema/2019/01/ratequote</rat:error>
177 </rat:schemaError>
178 </detail>
179 </soapenv:Fault>
180 </soapenv:Body>
181</soapenv:Envelope>
182
ANSWER
Answered 2021-Dec-16 at 17:14I would create a List Like:
1 ```
2
3
4
5 [System.Xml.Serialization.XmlElementAttribute("baseCommodities",
6 typeof(BaseCommoditiesType))]
7 [System.Xml.Serialization.XmlElementAttribute("fullCommodities",
8 typeof(FullCommoditiesType))]
9 public object Item {
10 get {
11 return this.itemField;
12 }
13 set {
14 this.itemField = value;
15 }
16 }
17
18[System.Xml.Serialization.XmlElement("commodity", typeof(FullCommodityType))]//added to request class recently
19
20 public object Items
21 {
22 get
23 {
24 return this.itemsField;
25 }
26 set
27 {
28 this.itemsField = value;
29 }
30 }
31
32
33```
34
35
36static void Main(string[] args)
37 {
38 RateQuoteService service = new RateQuoteService() ;
39
40 AuthenticationType authentication = new AuthenticationType();
41 authentication.user = "xxxxxxxx";
42 authentication.password = "xxxxxx";
43 service.auth = authentication;
44
45 rateRequest request = new rateRequest();
46 rateQuote quote = new rateQuote();
47
48 request.requestID = generateID();//just guid value for now
49
50 request.account = "xxxxxxx";
51
52 PointType origin = new PointType();
53 origin.city = "Shelby TownShip";
54 origin.postalCode = "48315";
55 origin.stateProvince = "MI";
56 origin.countryCode = "US";
57 request.originPoint = origin;
58
59 PointType destination = new PointType();
60 destination.city = "Fenton";
61 destination.postalCode = "48430";
62 destination.stateProvince = "MI";
63 destination.countryCode = "US";
64 request.destinationPoint = destination;
65
66 request.payor = "S";
67 request.terms = "P";
68
69 PickupType pickUP = new PickupType();
70 request.pickup = pickUP;
71 request.declaredValue = 1000.00M;
72 request.declaredValueSpecified = true;
73
74 request.stackable = YesNoBlankType.N;//enum
75 request.stackableSpecified = true;
76 request.linearFeet = "80";
77 request.foodWarehouse = "other";
78
79 request.declaredValueWaived = YesNoBlankType.N;//enum
80 request.declaredValueWaivedSpecified = true;
81
82 FullCommoditiesType fcom = new FullCommoditiesType();//just commodity property
83 FullCommodityType fcomtypes = new FullCommodityType();//all other properties
84
85 DimensionsType dim = new DimensionsType();
86 dim.length = "75";
87 dim.width = "50";
88 dim.height = "25";
89
90 fcomtypes.@class = 70.0M;
91 fcomtypes.weight = "500";
92 fcomtypes.pieces = "2";
93 fcomtypes.pieceType = PackagingType.PT;
94 fcomtypes.classSpecified = true;
95 fcomtypes.dimensions = dim;
96
97 //fcom.commodity = ????
98 //request.Item = ????//I'm assuming fcomtypes but dosent work
99
100request.Items = fcomtypes; //Hack - Now this adds what I need to the request object
101
102 //request.Item = fcomtypes as FullCommodityType;//dont work either
103
104 quote = service.getQuote(request);
105
106
107
108
109
110
111
112
113
114
115 }
116
117 <?xml version="1.0" encoding="utf-8"?>
118<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
119 <soap:Header>
120 <auth xmlns="http://ws.estesexpress.com/ratequote">
121 <user>xxxxxx</user>
122 <password>xxxxxxxx</password>
123 </auth>
124 </soap:Header>
125 <soap:Body>
126 <rateRequest xmlns="http://ws.estesexpress.com/schema/2019/01/ratequote">
127 <requestID>5fdbdbeedf474a439a54559750c2c5ea</requestID>
128 <account>xxxxxxx</account>
129 <originPoint>
130 <countryCode>US</countryCode>
131 <postalCode>48315</postalCode>
132 <city>Shelby TownShip</city>
133 <stateProvince>MI</stateProvince>
134 </originPoint>
135 <destinationPoint>
136 <countryCode>US</countryCode>
137 <postalCode>48430</postalCode>
138 <city>Fenton</city>
139 <stateProvince>MI</stateProvince>
140 </destinationPoint>
141 <payor>S</payor>
142 <terms>P</terms>
143 <pickup>
144 <date>0001-01-01</date>
145 </pickup>
146 <declaredValue>1000.00</declaredValue>
147 <declaredValueWaived>N</declaredValueWaived>
148 <stackable>N</stackable>
149 <linearFeet>80</linearFeet>
150 <foodWarehouse>other</foodWarehouse>
151 <commodity>
152 <class>70.0</class>
153 <weight>500</weight>
154 <pieces>2</pieces>
155 <pieceType>PT</pieceType>
156 <dimensions>
157 <length>75</length>
158 <width>50</width>
159 <height>25</height>
160 </dimensions>
161 <description>test</description>
162 </commodity>
163 </rateRequest>
164 </soap:Body>
165</soap:Envelope>
166 <?xml version='1.0' encoding='utf-8'?>
167<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
168 <soapenv:Header/>
169 <soapenv:Body>
170 <soapenv:Fault>
171 <faultcode>soapenv:Server</faultcode>
172 <faultstring>Schema validation error</faultstring>
173 <detail>
174 <rat:schemaError xmlns:rat="http://ws.estesexpress.com/ratequote">
175 <rat:error>Expected elements 'baseCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote fullCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote' before the end of the content in element rateRequest@http://ws.estesexpress.com/schema/2019/01/ratequote</rat:error>
176 <rat:error>Expected elements 'baseCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote fullCommodities@http://ws.estesexpress.com/schema/2019/01/ratequote' instead of 'commodity@http://ws.estesexpress.com/schema/2019/01/ratequote' here in element rateRequest@http://ws.estesexpress.com/schema/2019/01/ratequote</rat:error>
177 </rat:schemaError>
178 </detail>
179 </soapenv:Fault>
180 </soapenv:Body>
181</soapenv:Envelope>
182 List<FullCommodityType> productDesc = new List<FullCommodityType>();
183
184 productDesc.Add(new FullCommodityType()
185 {
186 @class = 70,
187 classSpecified = true,
188 weight = "500",
189 pieces = "2",
190 pieceType = PackagingType.PT,
191 dimensions = dim
192 });
193
194 List<FullCommoditiesType> products = new List<FullCommoditiesType>();
195
196 products.Add(new FullCommoditiesType()
197 {
198 commodity = productDesc.ToArray()
199 });
200
201 request.Item = products[0];
202
And you should probably add a date for pickup or you will get an unknown fault.
QUESTION
Creating Frontend-Backend connection through Mule ESB
Asked 2021-Dec-16 at 13:52I am currently learning about Mule ESB and I have a question bothering me. I created App with Frontend in React and Backend in Node.js and I would like my API to send data through ESB with it inserting some data from public SOAP API. Then data from REST API and SOAP API would be combined into one endpoint that my Frontend could use. Is that possible? Could someone recommend some place where I could read more about it? I went through documentation but couldn't find such case. I use for that PC version of Anypoint Studio
EDIT: There is actually one more public REST API from which I would like to combine data into my endpoint. So in total 3 API responses combined into one JSON response.
ANSWER
Answered 2021-Dec-16 at 13:52If I understand correctly you want to implement an API with Mule runtime (it is not called Mule ESB since some years ago), and that API should invoke some SOAP Web Services and REST APIs requests to other backends, then collect and transform the responses into a single JSON to answer to your client. That is completely possible to implement with Mule.
You need to create a application, in the application create a flow that is triggered with the HTTP Listener. Inside the flow use the Web Service Consumer to invoke SOAP Web Services. Use the HTTP Request connector to invoke REST APIs. Use the target variable configuration in each to save the responses to variables. Finally use the Transform component to transform the responses into a single JSON response before the end of the flow.
QUESTION
Quickbooks Web Connector "Response is not well-formed XML" error
Asked 2021-Nov-18 at 00:42We are using the Quickbooks Web Connector (QBWC) with the Consolibyte Quickbooks PHP Dev Kit. We have had a QBWC job working with this software for 4 years without major issues; however, now we are adding an additional QBWC job to access a different QB company file and a different handler. Every time this job runs it gets an error "Response is not well-formed XML":
120211117.18:47:19 UTC : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE
220211117.18:47:19 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True
320211117.18:47:19 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked *********************
420211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application.
520211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: SCS Consulting QB Integrator Prod 2
620211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): SCS Consulting QB Integrator Prod 2
720211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: https://nest.scscertified.com/quickbooks/qbwc_integrator.php?legal_entity=scs_consulting
820211117.18:47:19 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
920211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
1020211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
1120211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.2.0.71">
1220211117.18:47:20 UTC : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
1320211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
1420211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'SCS Consulting QB Integrator Prod 2', username = 'scsc_qb'
1520211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="scsc_qb"><password=<MaskedForSecurity>
1620211117.18:47:21 UTC : QBWebConnector.SOAPWebService.do_authenticate() : QBWC1012: Authentication failed due to following error message.
17Response is not well-formed XML.
18
The error starts on serverVersion() but the job doesn't actually fail until authenticate(). It seems that the problem is in the PHP handler; however, it is not logging any errors, and the dev kit log table shows proper XML:
120211117.18:47:19 UTC : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE
220211117.18:47:19 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True
320211117.18:47:19 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked *********************
420211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application.
520211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: SCS Consulting QB Integrator Prod 2
620211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): SCS Consulting QB Integrator Prod 2
720211117.18:47:19 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: https://nest.scscertified.com/quickbooks/qbwc_integrator.php?legal_entity=scs_consulting
820211117.18:47:19 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
920211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
1020211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
1120211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.2.0.71">
1220211117.18:47:20 UTC : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: <Response is not well-formed XML.>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
1320211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
1420211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'SCS Consulting QB Integrator Prod 2', username = 'scsc_qb'
1520211117.18:47:20 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="scsc_qb"><password=<MaskedForSecurity>
1620211117.18:47:21 UTC : QBWebConnector.SOAPWebService.do_authenticate() : QBWC1012: Authentication failed due to following error message.
17Response is not well-formed XML.
18 | Handler is starting up...: Array
19(
20 [qb_company_file] =>
21 [qbwc_min_version] =>
22 [qbwc_wait_before_next_update] =>
23 [qbwc_min_run_every_n_seconds] =>
24 [qbwc_version_warning_message] =>
25 [qbwc_version_error_message] =>
26 [qbwc_interactive_url] =>
27 [autoadd_missing_requestid] => 1
28 [check_valid_requestid] => 1
29 [server_version] => PHP QuickBooks SOAP Server v3.0 at /quickbooks/qbwc_integrator.php?legal_entity=scs_consulting
30 [authenticate] =>
31 [authenticate_dsn] =>
32 [map_application_identifiers] => 1
33 [allow_remote_addr] => Array
34 (
35 )
36
37 [deny_remote_addr] => Array
38 (
39 )
40
41 [convert_unix_newlines] => 1
42 [deny_concurrent_logins] =>
43 [deny_concurrent_timeout] => 60
44 [deny_reallyfast_logins] =>
45 [deny_reallyfast_timeout] => 600
46 [masking] => 1
47)
48
49 | 2021-11-17 10:47:20
50|-
51 | 697
52 |
53 | 0
54 | Incoming HTTP Headers: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)
55Content-Type: text/xml; charset=utf-8
56SOAPAction: "http://developer.intuit.com/serverVersion"
57Host: nest.scscertified.com
58Content-Length: 300
59Expect: 100-continue
60Connection: Keep-Alive
61
62 | 2021-11-17 10:47:20
63|-
64 | 698
65 |
66 | 0
67 | Incoming SOAP Request: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><serverVersion xmlns="http://developer.intuit.com/" /></soap:Body></soap:Envelope>
68 | 2021-11-17 10:47:20
69|-
70 | 699
71 |
72 | 0
73 | serverVersion()
74 | 2021-11-17 10:47:20
75|-
76 | 700
77 |
78 | 0
79 | Outgoing SOAP Response: <?xml version="1.0" encoding="UTF-8"?>
80 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
81 xmlns:ns1="http://developer.intuit.com/">
82 <SOAP-ENV:Body><ns1:serverVersionResponse><ns1:serverVersionResult>PHP QuickBooks SOAP Server v3.0 at /quickbooks/qbwc_integrator.php?legal_entity=scs_consulting</ns1:serverVersionResult></ns1:serverVersionResponse>
83 </SOAP-ENV:Body>
84 </SOAP-ENV:Envelope>
85
What I don't understand is that the PHP handler's XML response to serverVersion() looks fine (in fact identical to the XML returned by the working handler except for the URL), and this handler is logging no errors, but QBWC is rejecting it.
ANSWER
Answered 2021-Nov-18 at 00:42SOLVED - The XML response to QBWC had a single extra line feed before the XML declaration, which was causing QBWC to completely reject it. The source of the extra character was a PHP config file that had a blank line before the first <?php
tag. Doh!
QUESTION
PowerShell - how to escape {} in JSON string for a REST call
Asked 2021-Oct-20 at 15:00I'm reading an HTML file and need to pass it as a string parameter to a JSON call. The HTML has curly braces in it for css/styles. I was looking at this question, but mine is more around JSON special characters where that one was other escape characters. The file may also have [] characters.
1$HtmlFromFile2 = @"
2<html>
3 <style type="text/css">.LetterList {font-family:"arial"}</style>
4 <body>
5 To [firstname]:
6 This is a normal body with special JSON characters.
7 </body>
8</html>
9"@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace("`r", "").Replace("`n", "").Replace("`t","")
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace("{","\{").Replace("}","\}")
13
14Write-Host "After RegEx Fix"
15Write-Host $HtmlFromFileFixed
16
17$templateID = "Test_Temp7"
18
19
20$body = @"
21{ "uuid": "$templateID",
22 "subject": "My Email Subject",
23 "body": "$HtmlFromFileFixed"
24}
25"@
26
27# This also tests if our JSON is "well-formed", on extra or missing commas, braces, brackets, etc...
28$bodyJSON = ConvertFrom-Json $body
29
30# Write-Host $body
31
32$params = @{
33 Uri = 'https://stage-tms.demo.com/templates/email'
34 Headers = $headers
35 Method = 'POST'
36 Body = "$body"
37 ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41
I use the Convert-FromJSON as test. When that works, then usually the Invoke-RestMethod will work. When the Convert-FromJSON fails, the Invoke-RestMethod will come back with http statsu=400 and statusDescription="Bad Request".
Current Errors:
1$HtmlFromFile2 = @"
2<html>
3 <style type="text/css">.LetterList {font-family:"arial"}</style>
4 <body>
5 To [firstname]:
6 This is a normal body with special JSON characters.
7 </body>
8</html>
9"@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace("`r", "").Replace("`n", "").Replace("`t","")
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace("{","\{").Replace("}","\}")
13
14Write-Host "After RegEx Fix"
15Write-Host $HtmlFromFileFixed
16
17$templateID = "Test_Temp7"
18
19
20$body = @"
21{ "uuid": "$templateID",
22 "subject": "My Email Subject",
23 "body": "$HtmlFromFileFixed"
24}
25"@
26
27# This also tests if our JSON is "well-formed", on extra or missing commas, braces, brackets, etc...
28$bodyJSON = ConvertFrom-Json $body
29
30# Write-Host $body
31
32$params = @{
33 Uri = 'https://stage-tms.demo.com/templates/email'
34 Headers = $headers
35 Method = 'POST'
36 Body = "$body"
37 ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): { "uuid": "FEMAImport_Home_Test_Temp7",
42 "subject": "SBA Disaster Loan Assistance TestText",
43 "body": "<html> <style type="text/css">.sbaLetterList \{font-family:"arial"\}</style><body> This is a
44normal body with special JSON characters. </body></html>"
45}
46At C:\Scripts\TestJSONEscapeBraces.ps1:38 char:13
47+ $bodyJSON = ConvertFrom-Json $body
48+ ~~~~~~~~~~~~~~~~~~~~~~
49 + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
50 + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
51
Update 1: I did some more tests. I'm ending up with too may permutations of what works and what doesn't work. I can't include the entire HTML file I'm using; I need a technique to isolate errors and identify them. I was hoping ConvertFrom-JSON would do that for me.
From below, you can see different files I'm trying. The first one (the real file and the larger one fails both on the ConvertFrom-JSON and the REST/Post. The other two are now working.
1$HtmlFromFile2 = @"
2<html>
3 <style type="text/css">.LetterList {font-family:"arial"}</style>
4 <body>
5 To [firstname]:
6 This is a normal body with special JSON characters.
7 </body>
8</html>
9"@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace("`r", "").Replace("`n", "").Replace("`t","")
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace("{","\{").Replace("}","\}")
13
14Write-Host "After RegEx Fix"
15Write-Host $HtmlFromFileFixed
16
17$templateID = "Test_Temp7"
18
19
20$body = @"
21{ "uuid": "$templateID",
22 "subject": "My Email Subject",
23 "body": "$HtmlFromFileFixed"
24}
25"@
26
27# This also tests if our JSON is "well-formed", on extra or missing commas, braces, brackets, etc...
28$bodyJSON = ConvertFrom-Json $body
29
30# Write-Host $body
31
32$params = @{
33 Uri = 'https://stage-tms.demo.com/templates/email'
34 Headers = $headers
35 Method = 'POST'
36 Body = "$body"
37 ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): { "uuid": "FEMAImport_Home_Test_Temp7",
42 "subject": "SBA Disaster Loan Assistance TestText",
43 "body": "<html> <style type="text/css">.sbaLetterList \{font-family:"arial"\}</style><body> This is a
44normal body with special JSON characters. </body></html>"
45}
46At C:\Scripts\TestJSONEscapeBraces.ps1:38 char:13
47+ $bodyJSON = ConvertFrom-Json $body
48+ ~~~~~~~~~~~~~~~~~~~~~~
49 + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
50 + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
51 $HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home.html"
52#$HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home_SimpleTest.html"
53#$HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home_SimpleTestWithBraces.html"
54 $HtmlFromFile = Get-Content $HtmlBodyFilename -Raw #the -Raw option gets a string instead of an array of lins
55 $HtmlFromFileStripped = $HtmlFromFile.Replace("`r", "").Replace("`n", "").Replace("`t","")
56
I'm now able to read and process a small simple test file with curly braces in it. But when I point to the real HTML file on disk, I get errors, and don't know how to isolate it. I was probably assuming it was the curly brace.
If I use the ConvertFrom-JSON and the real HTML file, I get: ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (143): { "uuid": "FEMAImport_HomeFile_Test_Temp3", "subject": etc...
Now, if I remove the "ConvertFrom-JSON" and use the real HTML File, I get this error from the SOAP request: "The request was aborted: The connection was closed unexpectedly." Of course one difference is that the file is much bigger, about 83KB.
Before now, I have been getting a lot of 400 "Bad Request" errors, which is a useless error. I need to know what is wrong with the request.
ANSWER
Answered 2021-Oct-20 at 15:00Let Powershell do all the work for you and don't build the JSON string yourself, use an object:
1$HtmlFromFile2 = @"
2<html>
3 <style type="text/css">.LetterList {font-family:"arial"}</style>
4 <body>
5 To [firstname]:
6 This is a normal body with special JSON characters.
7 </body>
8</html>
9"@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace("`r", "").Replace("`n", "").Replace("`t","")
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace("{","\{").Replace("}","\}")
13
14Write-Host "After RegEx Fix"
15Write-Host $HtmlFromFileFixed
16
17$templateID = "Test_Temp7"
18
19
20$body = @"
21{ "uuid": "$templateID",
22 "subject": "My Email Subject",
23 "body": "$HtmlFromFileFixed"
24}
25"@
26
27# This also tests if our JSON is "well-formed", on extra or missing commas, braces, brackets, etc...
28$bodyJSON = ConvertFrom-Json $body
29
30# Write-Host $body
31
32$params = @{
33 Uri = 'https://stage-tms.demo.com/templates/email'
34 Headers = $headers
35 Method = 'POST'
36 Body = "$body"
37 ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): { "uuid": "FEMAImport_Home_Test_Temp7",
42 "subject": "SBA Disaster Loan Assistance TestText",
43 "body": "<html> <style type="text/css">.sbaLetterList \{font-family:"arial"\}</style><body> This is a
44normal body with special JSON characters. </body></html>"
45}
46At C:\Scripts\TestJSONEscapeBraces.ps1:38 char:13
47+ $bodyJSON = ConvertFrom-Json $body
48+ ~~~~~~~~~~~~~~~~~~~~~~
49 + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
50 + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
51 $HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home.html"
52#$HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home_SimpleTest.html"
53#$HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home_SimpleTestWithBraces.html"
54 $HtmlFromFile = Get-Content $HtmlBodyFilename -Raw #the -Raw option gets a string instead of an array of lins
55 $HtmlFromFileStripped = $HtmlFromFile.Replace("`r", "").Replace("`n", "").Replace("`t","")
56$body = ConvertTo-Json @{
57 uuid = $templateID
58 subject = "My Email Subject"
59 body = Get-Content $HtmlBodyFilename -Raw
60}
61
All special characters will be escaped automatically.
Credits to @Hazrelle, of course you don't even have to convert anything in this case, as Invoke-WebRequest
will do that for you:
1$HtmlFromFile2 = @"
2<html>
3 <style type="text/css">.LetterList {font-family:"arial"}</style>
4 <body>
5 To [firstname]:
6 This is a normal body with special JSON characters.
7 </body>
8</html>
9"@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace("`r", "").Replace("`n", "").Replace("`t","")
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace("{","\{").Replace("}","\}")
13
14Write-Host "After RegEx Fix"
15Write-Host $HtmlFromFileFixed
16
17$templateID = "Test_Temp7"
18
19
20$body = @"
21{ "uuid": "$templateID",
22 "subject": "My Email Subject",
23 "body": "$HtmlFromFileFixed"
24}
25"@
26
27# This also tests if our JSON is "well-formed", on extra or missing commas, braces, brackets, etc...
28$bodyJSON = ConvertFrom-Json $body
29
30# Write-Host $body
31
32$params = @{
33 Uri = 'https://stage-tms.demo.com/templates/email'
34 Headers = $headers
35 Method = 'POST'
36 Body = "$body"
37 ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): { "uuid": "FEMAImport_Home_Test_Temp7",
42 "subject": "SBA Disaster Loan Assistance TestText",
43 "body": "<html> <style type="text/css">.sbaLetterList \{font-family:"arial"\}</style><body> This is a
44normal body with special JSON characters. </body></html>"
45}
46At C:\Scripts\TestJSONEscapeBraces.ps1:38 char:13
47+ $bodyJSON = ConvertFrom-Json $body
48+ ~~~~~~~~~~~~~~~~~~~~~~
49 + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
50 + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
51 $HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home.html"
52#$HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home_SimpleTest.html"
53#$HtmlBodyFilename = "$PSScriptRoot\Emailbody_Home_SimpleTestWithBraces.html"
54 $HtmlFromFile = Get-Content $HtmlBodyFilename -Raw #the -Raw option gets a string instead of an array of lins
55 $HtmlFromFileStripped = $HtmlFromFile.Replace("`r", "").Replace("`n", "").Replace("`t","")
56$body = ConvertTo-Json @{
57 uuid = $templateID
58 subject = "My Email Subject"
59 body = Get-Content $HtmlBodyFilename -Raw
60}
61$params = @{
62 Uri = 'https://stage-tms.demo.com/templates/email'
63 Headers = $headers
64 Method = 'POST'
65 Body = @{
66 uuid = $templateID
67 subject = "My Email Subject"
68 body = Get-Content $HtmlBodyFilename -Raw
69 }
70 ContentType = 'application/json'
71}
72
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in SOAP
Tutorials and Learning Resources are not available at this moment for SOAP