Explore all SOAP open source software, libraries, packages, source code, cloud functions and APIs.

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

node-soap

by vpulim doticonjavascriptdoticon

star image 2737 doticonMIT

A SOAP client and server for node.js.

savon

by savonrb doticonrubydoticon

star image 1988 doticonMIT

Heavy metal SOAP client

python-zeep

by mvantellingen doticonpythondoticon

star image 1583 doticonNOASSERTION

A modern/fast python SOAP client based on lxml / requests

gowsdl

by hooklift doticongodoticon

star image 885 doticonMPL-2.0

WSDL2Go code generation as well as its SOAP proxy

cxf

by apache doticonjavadoticon

star image 758 doticonApache-2.0

Apache CXF

soap-client

by phpro doticonphpdoticon

star image 597 doticonMIT

A general purpose SOAP client for PHP

laravel-soap

by notfalsedev doticonphpdoticon

star image 571 doticonMIT

A soap client wrapper for Laravel

wsdl2go

by fiorix doticongodoticon

star image 395 doticonNOASSERTION

Command line tool to generate Go code from WSDL for SOAP XML services

PackageGenerator

by WsdlToPhp doticonphpdoticon

star image 339 doticonMIT

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP

Trending New libraries in SOAP

Soap

by Ricorocks-Digital-Agency doticonphpdoticon

star image 244 doticonMIT

A Laravel SOAP client that provides a clean interface for handling requests and responses.

laravel-soap

by CodeDredd doticonphpdoticon

star image 111 doticonMIT

Laravel Soap Client

sap-btp-service-operator

by SAP doticongodoticon

star image 85 doticonApache-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.

quarkus-cxf

by quarkiverse doticonjavadoticon

star image 56 doticonApache-2.0

Quarkus CXF Extension to support SOAP based web services.

savon

by netwo-io doticonrustdoticon

star image 21 doticon

A SOAP client generator for Rust

pylero

by RedHatQE doticonpythondoticon

star image 18 doticonMIT

Python wrapper for the Polarion WSDL API

RFEM_Python_Client

by Dlubal-Software doticonpythondoticon

star image 18 doticonMIT

Python client (or high-level functions) for RFEM 6 using Web Services, SOAP and WSDL

soap-client

by nikolic-bojan doticoncsharpdoticon

star image 17 doticon

Make SOAP requests using IHttpClientFactory in .NET Core

quarkus-cxf

by shumonsharif doticonjavadoticon

star image 17 doticonApache-2.0

Quarkus CXF Extension to support SOAP based web services.

Top Authors in SOAP

1

amusarra

6 Libraries

star icon22

2

goetas-webservices

5 Libraries

star icon193

3

WsdlToPhp

5 Libraries

star icon393

4

meng-tian

4 Libraries

star icon117

5

savonrb

4 Libraries

star icon2108

6

SAP

3 Libraries

star icon91

7

strongloop

3 Libraries

star icon392

8

contributte

3 Libraries

star icon98

9

laminas

2 Libraries

star icon42

10

tjsnell

2 Libraries

star icon8

1

6 Libraries

star icon22

2

5 Libraries

star icon193

3

5 Libraries

star icon393

4

4 Libraries

star icon117

5

4 Libraries

star icon2108

6

3 Libraries

star icon91

7

3 Libraries

star icon392

8

3 Libraries

star icon98

9

2 Libraries

star icon42

10

2 Libraries

star icon8

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:52

will 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:52

SOAP 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.

Source https://stackoverflow.com/questions/71791934

QUESTION

How can I make JavaFX re-initialize when Scene is swapped?

Asked 2022-Mar-10 at 12:25

I 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:25

I 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

Source https://stackoverflow.com/questions/71417675

QUESTION

WSDL - allow different order of DataMembers for SOAP messages

Asked 2022-Feb-22 at 09:43

We 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:43

You 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.

Source https://stackoverflow.com/questions/71218855

QUESTION

unable to consume SOAP service in zeep, python

Asked 2022-Jan-31 at 05:44

I 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:44

Your 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

Source https://stackoverflow.com/questions/70914567

QUESTION

how to edit the response fields in node-soap

Asked 2021-Dec-25 at 07:07

I 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:07

Omit 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&lt;definitions targetNamespace=&quot;http://app.com/app&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:app=&quot;http://app.com/app&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
2   
3   &lt;message name=&quot;SoapQuery&quot;&gt;
4      &lt;part name=&quot;TransType&quot; type=&quot;xsd:string&quot; /&gt;
5   &lt;/message&gt;
6
7   &lt;message name=&quot;SoapQueryResult&quot;&gt;
8      &lt;part name=&quot;ResponseCode&quot; type=&quot;xsd:string&quot;/&gt;
9      &lt;part name=&quot;ResultDesc&quot; type=&quot;xsd:string&quot; /&gt;
10   &lt;/message&gt;
11
12   &lt;portType name=&quot;SoapQuery_PortType&quot;&gt;
13      &lt;operation name=&quot;SoapQuery&quot;&gt;
14         &lt;input message=&quot;SoapQuery&quot; /&gt;
15         &lt;output message=&quot;SoapQueryResult&quot; /&gt;
16      &lt;/operation&gt;
17   &lt;/portType&gt;
18
19   &lt;binding name=&quot;SoapQuery_Binding&quot; type=&quot;SoapQuery_PortType&quot;&gt;
20      &lt;soap:binding style=&quot;rpc&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; /&gt;
21      &lt;operation name=&quot;SoapQuery&quot; style=&quot;document&quot;&gt;
22         &lt;soap:operation soapAction=&quot;SoapQuery&quot; /&gt;
23         &lt;soap:input&gt;
24            &lt;soap:body namespace=&quot;app&quot; use=&quot;literal&quot; /&gt;
25         &lt;/soap:input&gt;
26
27         &lt;soap:output&gt;
28            &lt;soap:body encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; use=&quot;literal&quot; /&gt;
29         &lt;/soap:output&gt;
30      &lt;/operation&gt;
31   &lt;/binding&gt;
32
33   &lt;service name=&quot;SoapQueryService&quot;&gt;
34      &lt;documentation&gt;WSDL File for SoapQueryService&lt;/documentation&gt;
35      &lt;port binding=&quot;SoapQuery_Binding&quot; name=&quot;SoapQuery_Port&quot;&gt;
36         &lt;soap:address location=&quot;http://localhost:8002/api/request&quot; /&gt;
37      &lt;/port&gt;
38   &lt;/service&gt;
39&lt;/definitions&gt;
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': &quot;sdfds&quot;,
49        });
50      }
51    }
52  }
53};
54
55&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
56    &lt;soapenv:Body&gt;
57        &lt;app:SoapQuery xmlns:app=&quot;http://app.com/app&quot;&gt;
58            &lt;TransType&gt;11124&lt;/TransType&gt;
59        &lt;/app:SoapQuery&gt;
60    &lt;/soapenv:Body&gt;
61&lt;/soapenv:Envelope&gt;
62&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
63&lt;soap:Envelope
64  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
65  xmlns:app=&quot;http://app.com/app&quot;&gt;
66  &lt;soap:Body&gt;
67    &lt;app:SoapQueryResponse&gt;
68      &lt;app:ResultCode&gt;0&lt;/app:ResultCode&gt;
69      &lt;app:ResultDesc&gt;sdfds&lt;/app:ResultDesc&gt;
70    &lt;/app:SoapQueryResponse&gt;
71  &lt;/soap:Body&gt;
72&lt;/soap:Envelope&gt;
73&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
74&lt;soap:Envelope
75  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
76  xmlns:app=&quot;http://app.com/app&quot;&gt;
77  &lt;soap:Body&gt;
78    &lt;app:SoapQueryResult&gt; &lt;!-- not - SoapQueryResponse --&gt;
79      &lt;ResultCode&gt;0&lt;/ResultCode&gt;  &lt;!-- notice there is no `app:` --&gt;
80      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt; &lt;!-- notice there is no `app:` --&gt;
81    &lt;/app:SoapQueryResult&gt;
82  &lt;/soap:Body&gt;
83&lt;/soap:Envelope&gt;
84&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
85&lt;soap:Envelope
86  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
87  xmlns:app=&quot;http://app.com/app&quot;&gt;
88  &lt;soap:Body&gt;
89    &lt;SoapQueryResult&gt; &lt;!-- notice there is no `app:` --&gt;
90      &lt;ResultCode&gt;0&lt;/ResultCode&gt;  
91      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt;
92    &lt;/SoapQueryResult&gt;
93  &lt;/soap:Body&gt;
94&lt;/soap:Envelope&gt;
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&lt;definitions targetNamespace=&quot;http://app.com/app&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:app=&quot;http://app.com/app&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
2   
3   &lt;message name=&quot;SoapQuery&quot;&gt;
4      &lt;part name=&quot;TransType&quot; type=&quot;xsd:string&quot; /&gt;
5   &lt;/message&gt;
6
7   &lt;message name=&quot;SoapQueryResult&quot;&gt;
8      &lt;part name=&quot;ResponseCode&quot; type=&quot;xsd:string&quot;/&gt;
9      &lt;part name=&quot;ResultDesc&quot; type=&quot;xsd:string&quot; /&gt;
10   &lt;/message&gt;
11
12   &lt;portType name=&quot;SoapQuery_PortType&quot;&gt;
13      &lt;operation name=&quot;SoapQuery&quot;&gt;
14         &lt;input message=&quot;SoapQuery&quot; /&gt;
15         &lt;output message=&quot;SoapQueryResult&quot; /&gt;
16      &lt;/operation&gt;
17   &lt;/portType&gt;
18
19   &lt;binding name=&quot;SoapQuery_Binding&quot; type=&quot;SoapQuery_PortType&quot;&gt;
20      &lt;soap:binding style=&quot;rpc&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; /&gt;
21      &lt;operation name=&quot;SoapQuery&quot; style=&quot;document&quot;&gt;
22         &lt;soap:operation soapAction=&quot;SoapQuery&quot; /&gt;
23         &lt;soap:input&gt;
24            &lt;soap:body namespace=&quot;app&quot; use=&quot;literal&quot; /&gt;
25         &lt;/soap:input&gt;
26
27         &lt;soap:output&gt;
28            &lt;soap:body encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; use=&quot;literal&quot; /&gt;
29         &lt;/soap:output&gt;
30      &lt;/operation&gt;
31   &lt;/binding&gt;
32
33   &lt;service name=&quot;SoapQueryService&quot;&gt;
34      &lt;documentation&gt;WSDL File for SoapQueryService&lt;/documentation&gt;
35      &lt;port binding=&quot;SoapQuery_Binding&quot; name=&quot;SoapQuery_Port&quot;&gt;
36         &lt;soap:address location=&quot;http://localhost:8002/api/request&quot; /&gt;
37      &lt;/port&gt;
38   &lt;/service&gt;
39&lt;/definitions&gt;
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': &quot;sdfds&quot;,
49        });
50      }
51    }
52  }
53};
54
55&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
56    &lt;soapenv:Body&gt;
57        &lt;app:SoapQuery xmlns:app=&quot;http://app.com/app&quot;&gt;
58            &lt;TransType&gt;11124&lt;/TransType&gt;
59        &lt;/app:SoapQuery&gt;
60    &lt;/soapenv:Body&gt;
61&lt;/soapenv:Envelope&gt;
62&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
63&lt;soap:Envelope
64  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
65  xmlns:app=&quot;http://app.com/app&quot;&gt;
66  &lt;soap:Body&gt;
67    &lt;app:SoapQueryResponse&gt;
68      &lt;app:ResultCode&gt;0&lt;/app:ResultCode&gt;
69      &lt;app:ResultDesc&gt;sdfds&lt;/app:ResultDesc&gt;
70    &lt;/app:SoapQueryResponse&gt;
71  &lt;/soap:Body&gt;
72&lt;/soap:Envelope&gt;
73&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
74&lt;soap:Envelope
75  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
76  xmlns:app=&quot;http://app.com/app&quot;&gt;
77  &lt;soap:Body&gt;
78    &lt;app:SoapQueryResult&gt; &lt;!-- not - SoapQueryResponse --&gt;
79      &lt;ResultCode&gt;0&lt;/ResultCode&gt;  &lt;!-- notice there is no `app:` --&gt;
80      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt; &lt;!-- notice there is no `app:` --&gt;
81    &lt;/app:SoapQueryResult&gt;
82  &lt;/soap:Body&gt;
83&lt;/soap:Envelope&gt;
84&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
85&lt;soap:Envelope
86  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
87  xmlns:app=&quot;http://app.com/app&quot;&gt;
88  &lt;soap:Body&gt;
89    &lt;SoapQueryResult&gt; &lt;!-- notice there is no `app:` --&gt;
90      &lt;ResultCode&gt;0&lt;/ResultCode&gt;  
91      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt;
92    &lt;/SoapQueryResult&gt;
93  &lt;/soap:Body&gt;
94&lt;/soap:Envelope&gt;
95 &lt;message name=&quot;SoapQueryResult&quot; targetNamespace=&quot;app&quot;&gt;
96      &lt;part name=&quot;ResponseCode&quot; type=&quot;xsd:string&quot;/&gt;
97      &lt;part name=&quot;ResultDesc&quot; type=&quot;xsd:string&quot; /&gt;
98 &lt;/message&gt;
99

and you'll get your desired output

1&lt;definitions targetNamespace=&quot;http://app.com/app&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:app=&quot;http://app.com/app&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
2   
3   &lt;message name=&quot;SoapQuery&quot;&gt;
4      &lt;part name=&quot;TransType&quot; type=&quot;xsd:string&quot; /&gt;
5   &lt;/message&gt;
6
7   &lt;message name=&quot;SoapQueryResult&quot;&gt;
8      &lt;part name=&quot;ResponseCode&quot; type=&quot;xsd:string&quot;/&gt;
9      &lt;part name=&quot;ResultDesc&quot; type=&quot;xsd:string&quot; /&gt;
10   &lt;/message&gt;
11
12   &lt;portType name=&quot;SoapQuery_PortType&quot;&gt;
13      &lt;operation name=&quot;SoapQuery&quot;&gt;
14         &lt;input message=&quot;SoapQuery&quot; /&gt;
15         &lt;output message=&quot;SoapQueryResult&quot; /&gt;
16      &lt;/operation&gt;
17   &lt;/portType&gt;
18
19   &lt;binding name=&quot;SoapQuery_Binding&quot; type=&quot;SoapQuery_PortType&quot;&gt;
20      &lt;soap:binding style=&quot;rpc&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; /&gt;
21      &lt;operation name=&quot;SoapQuery&quot; style=&quot;document&quot;&gt;
22         &lt;soap:operation soapAction=&quot;SoapQuery&quot; /&gt;
23         &lt;soap:input&gt;
24            &lt;soap:body namespace=&quot;app&quot; use=&quot;literal&quot; /&gt;
25         &lt;/soap:input&gt;
26
27         &lt;soap:output&gt;
28            &lt;soap:body encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; use=&quot;literal&quot; /&gt;
29         &lt;/soap:output&gt;
30      &lt;/operation&gt;
31   &lt;/binding&gt;
32
33   &lt;service name=&quot;SoapQueryService&quot;&gt;
34      &lt;documentation&gt;WSDL File for SoapQueryService&lt;/documentation&gt;
35      &lt;port binding=&quot;SoapQuery_Binding&quot; name=&quot;SoapQuery_Port&quot;&gt;
36         &lt;soap:address location=&quot;http://localhost:8002/api/request&quot; /&gt;
37      &lt;/port&gt;
38   &lt;/service&gt;
39&lt;/definitions&gt;
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': &quot;sdfds&quot;,
49        });
50      }
51    }
52  }
53};
54
55&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
56    &lt;soapenv:Body&gt;
57        &lt;app:SoapQuery xmlns:app=&quot;http://app.com/app&quot;&gt;
58            &lt;TransType&gt;11124&lt;/TransType&gt;
59        &lt;/app:SoapQuery&gt;
60    &lt;/soapenv:Body&gt;
61&lt;/soapenv:Envelope&gt;
62&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
63&lt;soap:Envelope
64  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
65  xmlns:app=&quot;http://app.com/app&quot;&gt;
66  &lt;soap:Body&gt;
67    &lt;app:SoapQueryResponse&gt;
68      &lt;app:ResultCode&gt;0&lt;/app:ResultCode&gt;
69      &lt;app:ResultDesc&gt;sdfds&lt;/app:ResultDesc&gt;
70    &lt;/app:SoapQueryResponse&gt;
71  &lt;/soap:Body&gt;
72&lt;/soap:Envelope&gt;
73&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
74&lt;soap:Envelope
75  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
76  xmlns:app=&quot;http://app.com/app&quot;&gt;
77  &lt;soap:Body&gt;
78    &lt;app:SoapQueryResult&gt; &lt;!-- not - SoapQueryResponse --&gt;
79      &lt;ResultCode&gt;0&lt;/ResultCode&gt;  &lt;!-- notice there is no `app:` --&gt;
80      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt; &lt;!-- notice there is no `app:` --&gt;
81    &lt;/app:SoapQueryResult&gt;
82  &lt;/soap:Body&gt;
83&lt;/soap:Envelope&gt;
84&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
85&lt;soap:Envelope
86  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
87  xmlns:app=&quot;http://app.com/app&quot;&gt;
88  &lt;soap:Body&gt;
89    &lt;SoapQueryResult&gt; &lt;!-- notice there is no `app:` --&gt;
90      &lt;ResultCode&gt;0&lt;/ResultCode&gt;  
91      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt;
92    &lt;/SoapQueryResult&gt;
93  &lt;/soap:Body&gt;
94&lt;/soap:Envelope&gt;
95 &lt;message name=&quot;SoapQueryResult&quot; targetNamespace=&quot;app&quot;&gt;
96      &lt;part name=&quot;ResponseCode&quot; type=&quot;xsd:string&quot;/&gt;
97      &lt;part name=&quot;ResultDesc&quot; type=&quot;xsd:string&quot; /&gt;
98 &lt;/message&gt;
99&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
100&lt;soap:Envelope
101  xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
102  xmlns:app=&quot;http://app.com/app&quot;&gt;
103  &lt;soap:Body&gt;
104    &lt;app:SoapQueryResult&gt;
105      &lt;ResultCode&gt;0&lt;/ResultCode&gt;
106      &lt;ResultDesc&gt;sdfds&lt;/ResultDesc&gt;
107    &lt;/app:SoapQueryResult&gt;
108  &lt;/soap:Body&gt;
109&lt;/soap:Envelope&gt;
110

Source https://stackoverflow.com/questions/70453937

QUESTION

Anypoint Studio problem with JSON into XML transformation

Asked 2021-Dec-20 at 21:26

I 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&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
2&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
3  &lt;soap:Body&gt;
4    &lt;NumberToDollars xmlns=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
5      &lt;dNum&gt;47.92&lt;/dNum&gt;
6    &lt;/NumberToDollars&gt;
7  &lt;/soap:Body&gt;
8&lt;/soap:Envelope&gt; 
9

but when I use this as example for Transform Messages module it creates:

1&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
2&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
3  &lt;soap:Body&gt;
4    &lt;NumberToDollars xmlns=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
5      &lt;dNum&gt;47.92&lt;/dNum&gt;
6    &lt;/NumberToDollars&gt;
7  &lt;/soap:Body&gt;
8&lt;/soap:Envelope&gt; 
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&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
2&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
3  &lt;soap:Body&gt;
4    &lt;NumberToDollars xmlns=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
5      &lt;dNum&gt;47.92&lt;/dNum&gt;
6    &lt;/NumberToDollars&gt;
7  &lt;/soap:Body&gt;
8&lt;/soap:Envelope&gt; 
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&lt;?xml version='1.0' encoding='UTF-8'?&gt;
24&lt;ns00:Envelope xmlns:ns00=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
25  &lt;ns00:Body&gt;
26    &lt;ns01:NumberToDollars xmlns:ns01=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
27      &lt;ns01:dNum&gt;47.92&lt;/ns01:dNum&gt;
28    &lt;/ns01:NumberToDollars&gt;
29  &lt;/ns00:Body&gt;
30&lt;/ns00:Envelope&gt;
31

I know I can change it manually and I managed to get it to look like this:

1&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
2&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
3  &lt;soap:Body&gt;
4    &lt;NumberToDollars xmlns=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
5      &lt;dNum&gt;47.92&lt;/dNum&gt;
6    &lt;/NumberToDollars&gt;
7  &lt;/soap:Body&gt;
8&lt;/soap:Envelope&gt; 
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&lt;?xml version='1.0' encoding='UTF-8'?&gt;
24&lt;ns00:Envelope xmlns:ns00=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
25  &lt;ns00:Body&gt;
26    &lt;ns01:NumberToDollars xmlns:ns01=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
27      &lt;ns01:dNum&gt;47.92&lt;/ns01:dNum&gt;
28    &lt;/ns01:NumberToDollars&gt;
29  &lt;/ns00:Body&gt;
30&lt;/ns00:Envelope&gt;
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&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
2&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
3  &lt;soap:Body&gt;
4    &lt;NumberToDollars xmlns=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
5      &lt;dNum&gt;47.92&lt;/dNum&gt;
6    &lt;/NumberToDollars&gt;
7  &lt;/soap:Body&gt;
8&lt;/soap:Envelope&gt; 
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&lt;?xml version='1.0' encoding='UTF-8'?&gt;
24&lt;ns00:Envelope xmlns:ns00=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
25  &lt;ns00:Body&gt;
26    &lt;ns01:NumberToDollars xmlns:ns01=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
27      &lt;ns01:dNum&gt;47.92&lt;/ns01:dNum&gt;
28    &lt;/ns01:NumberToDollars&gt;
29  &lt;/ns00:Body&gt;
30&lt;/ns00:Envelope&gt;
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&lt;?xml version='1.0' encoding='UTF-8'?&gt;
46&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
47  &lt;soap:Body&gt;
48    &lt;NumberToDollars&gt;
49      &lt;dNum&gt;47.92&lt;/dNum&gt;
50    &lt;/NumberToDollars&gt;
51  &lt;/soap:Body&gt;
52&lt;/soap:Envelope&gt;
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:26

A way to do that is to define xmlns as if it were a normal attribute:

1&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
2&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
3  &lt;soap:Body&gt;
4    &lt;NumberToDollars xmlns=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
5      &lt;dNum&gt;47.92&lt;/dNum&gt;
6    &lt;/NumberToDollars&gt;
7  &lt;/soap:Body&gt;
8&lt;/soap:Envelope&gt; 
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&lt;?xml version='1.0' encoding='UTF-8'?&gt;
24&lt;ns00:Envelope xmlns:ns00=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
25  &lt;ns00:Body&gt;
26    &lt;ns01:NumberToDollars xmlns:ns01=&quot;http://www.dataaccess.com/webservicesserver/&quot;&gt;
27      &lt;ns01:dNum&gt;47.92&lt;/ns01:dNum&gt;
28    &lt;/ns01:NumberToDollars&gt;
29  &lt;/ns00:Body&gt;
30&lt;/ns00:Envelope&gt;
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&lt;?xml version='1.0' encoding='UTF-8'?&gt;
46&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
47  &lt;soap:Body&gt;
48    &lt;NumberToDollars&gt;
49      &lt;dNum&gt;47.92&lt;/dNum&gt;
50    &lt;/NumberToDollars&gt;
51  &lt;/soap:Body&gt;
52&lt;/soap:Envelope&gt;
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: &quot;http://www.dataaccess.com/webservicesserver/&quot;): {
62                dNum: payload.decimal
63            }
64        }
65    }
66}
67

Source https://stackoverflow.com/questions/70427882

QUESTION

Estes Express Api Version 4.0 Rate Quote

Asked 2021-Dec-16 at 17:19

I 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(&quot;baseCommodities&quot;, 
6        typeof(BaseCommoditiesType))]
7        [System.Xml.Serialization.XmlElementAttribute(&quot;fullCommodities&quot;, 
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(&quot;commodity&quot;, 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(&quot;baseCommodities&quot;, 
6        typeof(BaseCommoditiesType))]
7        [System.Xml.Serialization.XmlElementAttribute(&quot;fullCommodities&quot;, 
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(&quot;commodity&quot;, 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 = &quot;xxxxxxxx&quot;;
42        authentication.password = &quot;xxxxxx&quot;;
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 = &quot;xxxxxxx&quot;;
51
52        PointType origin = new PointType();
53        origin.city = &quot;Shelby TownShip&quot;;
54        origin.postalCode = &quot;48315&quot;;
55        origin.stateProvince = &quot;MI&quot;;
56        origin.countryCode = &quot;US&quot;;
57        request.originPoint = origin;
58
59        PointType destination = new PointType();
60        destination.city = &quot;Fenton&quot;;
61        destination.postalCode = &quot;48430&quot;;
62        destination.stateProvince = &quot;MI&quot;;
63        destination.countryCode = &quot;US&quot;;
64        request.destinationPoint = destination;
65
66        request.payor = &quot;S&quot;;
67        request.terms = &quot;P&quot;;
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 = &quot;80&quot;;
77        request.foodWarehouse = &quot;other&quot;;
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 = &quot;75&quot;;
87        dim.width = &quot;50&quot;;
88        dim.height = &quot;25&quot;;
89
90        fcomtypes.@class = 70.0M;
91        fcomtypes.weight = &quot;500&quot;;
92        fcomtypes.pieces = &quot;2&quot;;
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(&quot;baseCommodities&quot;, 
6        typeof(BaseCommoditiesType))]
7        [System.Xml.Serialization.XmlElementAttribute(&quot;fullCommodities&quot;, 
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(&quot;commodity&quot;, 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 = &quot;xxxxxxxx&quot;;
42        authentication.password = &quot;xxxxxx&quot;;
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 = &quot;xxxxxxx&quot;;
51
52        PointType origin = new PointType();
53        origin.city = &quot;Shelby TownShip&quot;;
54        origin.postalCode = &quot;48315&quot;;
55        origin.stateProvince = &quot;MI&quot;;
56        origin.countryCode = &quot;US&quot;;
57        request.originPoint = origin;
58
59        PointType destination = new PointType();
60        destination.city = &quot;Fenton&quot;;
61        destination.postalCode = &quot;48430&quot;;
62        destination.stateProvince = &quot;MI&quot;;
63        destination.countryCode = &quot;US&quot;;
64        request.destinationPoint = destination;
65
66        request.payor = &quot;S&quot;;
67        request.terms = &quot;P&quot;;
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 = &quot;80&quot;;
77        request.foodWarehouse = &quot;other&quot;;
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 = &quot;75&quot;;
87        dim.width = &quot;50&quot;;
88        dim.height = &quot;25&quot;;
89
90        fcomtypes.@class = 70.0M;
91        fcomtypes.weight = &quot;500&quot;;
92        fcomtypes.pieces = &quot;2&quot;;
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 &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
118&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
119       &lt;soap:Header&gt;
120              &lt;auth xmlns=&quot;http://ws.estesexpress.com/ratequote&quot;&gt;
121                     &lt;user&gt;xxxxxx&lt;/user&gt;
122                     &lt;password&gt;xxxxxxxx&lt;/password&gt;
123              &lt;/auth&gt;
124       &lt;/soap:Header&gt;
125       &lt;soap:Body&gt;
126              &lt;rateRequest xmlns=&quot;http://ws.estesexpress.com/schema/2019/01/ratequote&quot;&gt;
127                     &lt;requestID&gt;5fdbdbeedf474a439a54559750c2c5ea&lt;/requestID&gt;
128                     &lt;account&gt;xxxxxxx&lt;/account&gt;
129                     &lt;originPoint&gt;
130                           &lt;countryCode&gt;US&lt;/countryCode&gt;
131                           &lt;postalCode&gt;48315&lt;/postalCode&gt;
132                           &lt;city&gt;Shelby TownShip&lt;/city&gt;
133                           &lt;stateProvince&gt;MI&lt;/stateProvince&gt;
134                     &lt;/originPoint&gt;
135                     &lt;destinationPoint&gt;
136                           &lt;countryCode&gt;US&lt;/countryCode&gt;
137                           &lt;postalCode&gt;48430&lt;/postalCode&gt;
138                           &lt;city&gt;Fenton&lt;/city&gt;
139                           &lt;stateProvince&gt;MI&lt;/stateProvince&gt;
140                     &lt;/destinationPoint&gt;
141                     &lt;payor&gt;S&lt;/payor&gt;
142                     &lt;terms&gt;P&lt;/terms&gt;
143                     &lt;pickup&gt;
144                           &lt;date&gt;0001-01-01&lt;/date&gt;
145                     &lt;/pickup&gt;
146                     &lt;declaredValue&gt;1000.00&lt;/declaredValue&gt;
147                     &lt;declaredValueWaived&gt;N&lt;/declaredValueWaived&gt;
148                     &lt;stackable&gt;N&lt;/stackable&gt;
149                     &lt;linearFeet&gt;80&lt;/linearFeet&gt;
150                     &lt;foodWarehouse&gt;other&lt;/foodWarehouse&gt;
151                     &lt;commodity&gt;
152                           &lt;class&gt;70.0&lt;/class&gt;
153                           &lt;weight&gt;500&lt;/weight&gt;
154                           &lt;pieces&gt;2&lt;/pieces&gt;
155                           &lt;pieceType&gt;PT&lt;/pieceType&gt;
156                           &lt;dimensions&gt;
157                                  &lt;length&gt;75&lt;/length&gt;
158                                  &lt;width&gt;50&lt;/width&gt;
159                                  &lt;height&gt;25&lt;/height&gt;
160                           &lt;/dimensions&gt;
161                           &lt;description&gt;test&lt;/description&gt;
162                     &lt;/commodity&gt;
163              &lt;/rateRequest&gt;
164       &lt;/soap:Body&gt;
165&lt;/soap:Envelope&gt;
166

Expected Fault Back:

1    ```
2      
3       
4
5 [System.Xml.Serialization.XmlElementAttribute(&quot;baseCommodities&quot;, 
6        typeof(BaseCommoditiesType))]
7        [System.Xml.Serialization.XmlElementAttribute(&quot;fullCommodities&quot;, 
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(&quot;commodity&quot;, 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 = &quot;xxxxxxxx&quot;;
42        authentication.password = &quot;xxxxxx&quot;;
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 = &quot;xxxxxxx&quot;;
51
52        PointType origin = new PointType();
53        origin.city = &quot;Shelby TownShip&quot;;
54        origin.postalCode = &quot;48315&quot;;
55        origin.stateProvince = &quot;MI&quot;;
56        origin.countryCode = &quot;US&quot;;
57        request.originPoint = origin;
58
59        PointType destination = new PointType();
60        destination.city = &quot;Fenton&quot;;
61        destination.postalCode = &quot;48430&quot;;
62        destination.stateProvince = &quot;MI&quot;;
63        destination.countryCode = &quot;US&quot;;
64        request.destinationPoint = destination;
65
66        request.payor = &quot;S&quot;;
67        request.terms = &quot;P&quot;;
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 = &quot;80&quot;;
77        request.foodWarehouse = &quot;other&quot;;
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 = &quot;75&quot;;
87        dim.width = &quot;50&quot;;
88        dim.height = &quot;25&quot;;
89
90        fcomtypes.@class = 70.0M;
91        fcomtypes.weight = &quot;500&quot;;
92        fcomtypes.pieces = &quot;2&quot;;
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 &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
118&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
119       &lt;soap:Header&gt;
120              &lt;auth xmlns=&quot;http://ws.estesexpress.com/ratequote&quot;&gt;
121                     &lt;user&gt;xxxxxx&lt;/user&gt;
122                     &lt;password&gt;xxxxxxxx&lt;/password&gt;
123              &lt;/auth&gt;
124       &lt;/soap:Header&gt;
125       &lt;soap:Body&gt;
126              &lt;rateRequest xmlns=&quot;http://ws.estesexpress.com/schema/2019/01/ratequote&quot;&gt;
127                     &lt;requestID&gt;5fdbdbeedf474a439a54559750c2c5ea&lt;/requestID&gt;
128                     &lt;account&gt;xxxxxxx&lt;/account&gt;
129                     &lt;originPoint&gt;
130                           &lt;countryCode&gt;US&lt;/countryCode&gt;
131                           &lt;postalCode&gt;48315&lt;/postalCode&gt;
132                           &lt;city&gt;Shelby TownShip&lt;/city&gt;
133                           &lt;stateProvince&gt;MI&lt;/stateProvince&gt;
134                     &lt;/originPoint&gt;
135                     &lt;destinationPoint&gt;
136                           &lt;countryCode&gt;US&lt;/countryCode&gt;
137                           &lt;postalCode&gt;48430&lt;/postalCode&gt;
138                           &lt;city&gt;Fenton&lt;/city&gt;
139                           &lt;stateProvince&gt;MI&lt;/stateProvince&gt;
140                     &lt;/destinationPoint&gt;
141                     &lt;payor&gt;S&lt;/payor&gt;
142                     &lt;terms&gt;P&lt;/terms&gt;
143                     &lt;pickup&gt;
144                           &lt;date&gt;0001-01-01&lt;/date&gt;
145                     &lt;/pickup&gt;
146                     &lt;declaredValue&gt;1000.00&lt;/declaredValue&gt;
147                     &lt;declaredValueWaived&gt;N&lt;/declaredValueWaived&gt;
148                     &lt;stackable&gt;N&lt;/stackable&gt;
149                     &lt;linearFeet&gt;80&lt;/linearFeet&gt;
150                     &lt;foodWarehouse&gt;other&lt;/foodWarehouse&gt;
151                     &lt;commodity&gt;
152                           &lt;class&gt;70.0&lt;/class&gt;
153                           &lt;weight&gt;500&lt;/weight&gt;
154                           &lt;pieces&gt;2&lt;/pieces&gt;
155                           &lt;pieceType&gt;PT&lt;/pieceType&gt;
156                           &lt;dimensions&gt;
157                                  &lt;length&gt;75&lt;/length&gt;
158                                  &lt;width&gt;50&lt;/width&gt;
159                                  &lt;height&gt;25&lt;/height&gt;
160                           &lt;/dimensions&gt;
161                           &lt;description&gt;test&lt;/description&gt;
162                     &lt;/commodity&gt;
163              &lt;/rateRequest&gt;
164       &lt;/soap:Body&gt;
165&lt;/soap:Envelope&gt;
166 &lt;?xml version='1.0' encoding='utf-8'?&gt;
167&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
168    &lt;soapenv:Header/&gt;
169    &lt;soapenv:Body&gt;
170        &lt;soapenv:Fault&gt;
171            &lt;faultcode&gt;soapenv:Server&lt;/faultcode&gt;
172            &lt;faultstring&gt;Schema validation error&lt;/faultstring&gt;
173            &lt;detail&gt;
174                &lt;rat:schemaError xmlns:rat=&quot;http://ws.estesexpress.com/ratequote&quot;&gt;
175                    &lt;rat:error&gt;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&lt;/rat:error&gt;
176                    &lt;rat:error&gt;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&lt;/rat:error&gt;
177                &lt;/rat:schemaError&gt;
178            &lt;/detail&gt;
179        &lt;/soapenv:Fault&gt;
180    &lt;/soapenv:Body&gt;
181&lt;/soapenv:Envelope&gt;
182

ANSWER

Answered 2021-Dec-16 at 17:14

I would create a List Like:

1    ```
2      
3       
4
5 [System.Xml.Serialization.XmlElementAttribute(&quot;baseCommodities&quot;, 
6        typeof(BaseCommoditiesType))]
7        [System.Xml.Serialization.XmlElementAttribute(&quot;fullCommodities&quot;, 
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(&quot;commodity&quot;, 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 = &quot;xxxxxxxx&quot;;
42        authentication.password = &quot;xxxxxx&quot;;
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 = &quot;xxxxxxx&quot;;
51
52        PointType origin = new PointType();
53        origin.city = &quot;Shelby TownShip&quot;;
54        origin.postalCode = &quot;48315&quot;;
55        origin.stateProvince = &quot;MI&quot;;
56        origin.countryCode = &quot;US&quot;;
57        request.originPoint = origin;
58
59        PointType destination = new PointType();
60        destination.city = &quot;Fenton&quot;;
61        destination.postalCode = &quot;48430&quot;;
62        destination.stateProvince = &quot;MI&quot;;
63        destination.countryCode = &quot;US&quot;;
64        request.destinationPoint = destination;
65
66        request.payor = &quot;S&quot;;
67        request.terms = &quot;P&quot;;
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 = &quot;80&quot;;
77        request.foodWarehouse = &quot;other&quot;;
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 = &quot;75&quot;;
87        dim.width = &quot;50&quot;;
88        dim.height = &quot;25&quot;;
89
90        fcomtypes.@class = 70.0M;
91        fcomtypes.weight = &quot;500&quot;;
92        fcomtypes.pieces = &quot;2&quot;;
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 &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
118&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
119       &lt;soap:Header&gt;
120              &lt;auth xmlns=&quot;http://ws.estesexpress.com/ratequote&quot;&gt;
121                     &lt;user&gt;xxxxxx&lt;/user&gt;
122                     &lt;password&gt;xxxxxxxx&lt;/password&gt;
123              &lt;/auth&gt;
124       &lt;/soap:Header&gt;
125       &lt;soap:Body&gt;
126              &lt;rateRequest xmlns=&quot;http://ws.estesexpress.com/schema/2019/01/ratequote&quot;&gt;
127                     &lt;requestID&gt;5fdbdbeedf474a439a54559750c2c5ea&lt;/requestID&gt;
128                     &lt;account&gt;xxxxxxx&lt;/account&gt;
129                     &lt;originPoint&gt;
130                           &lt;countryCode&gt;US&lt;/countryCode&gt;
131                           &lt;postalCode&gt;48315&lt;/postalCode&gt;
132                           &lt;city&gt;Shelby TownShip&lt;/city&gt;
133                           &lt;stateProvince&gt;MI&lt;/stateProvince&gt;
134                     &lt;/originPoint&gt;
135                     &lt;destinationPoint&gt;
136                           &lt;countryCode&gt;US&lt;/countryCode&gt;
137                           &lt;postalCode&gt;48430&lt;/postalCode&gt;
138                           &lt;city&gt;Fenton&lt;/city&gt;
139                           &lt;stateProvince&gt;MI&lt;/stateProvince&gt;
140                     &lt;/destinationPoint&gt;
141                     &lt;payor&gt;S&lt;/payor&gt;
142                     &lt;terms&gt;P&lt;/terms&gt;
143                     &lt;pickup&gt;
144                           &lt;date&gt;0001-01-01&lt;/date&gt;
145                     &lt;/pickup&gt;
146                     &lt;declaredValue&gt;1000.00&lt;/declaredValue&gt;
147                     &lt;declaredValueWaived&gt;N&lt;/declaredValueWaived&gt;
148                     &lt;stackable&gt;N&lt;/stackable&gt;
149                     &lt;linearFeet&gt;80&lt;/linearFeet&gt;
150                     &lt;foodWarehouse&gt;other&lt;/foodWarehouse&gt;
151                     &lt;commodity&gt;
152                           &lt;class&gt;70.0&lt;/class&gt;
153                           &lt;weight&gt;500&lt;/weight&gt;
154                           &lt;pieces&gt;2&lt;/pieces&gt;
155                           &lt;pieceType&gt;PT&lt;/pieceType&gt;
156                           &lt;dimensions&gt;
157                                  &lt;length&gt;75&lt;/length&gt;
158                                  &lt;width&gt;50&lt;/width&gt;
159                                  &lt;height&gt;25&lt;/height&gt;
160                           &lt;/dimensions&gt;
161                           &lt;description&gt;test&lt;/description&gt;
162                     &lt;/commodity&gt;
163              &lt;/rateRequest&gt;
164       &lt;/soap:Body&gt;
165&lt;/soap:Envelope&gt;
166 &lt;?xml version='1.0' encoding='utf-8'?&gt;
167&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
168    &lt;soapenv:Header/&gt;
169    &lt;soapenv:Body&gt;
170        &lt;soapenv:Fault&gt;
171            &lt;faultcode&gt;soapenv:Server&lt;/faultcode&gt;
172            &lt;faultstring&gt;Schema validation error&lt;/faultstring&gt;
173            &lt;detail&gt;
174                &lt;rat:schemaError xmlns:rat=&quot;http://ws.estesexpress.com/ratequote&quot;&gt;
175                    &lt;rat:error&gt;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&lt;/rat:error&gt;
176                    &lt;rat:error&gt;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&lt;/rat:error&gt;
177                &lt;/rat:schemaError&gt;
178            &lt;/detail&gt;
179        &lt;/soapenv:Fault&gt;
180    &lt;/soapenv:Body&gt;
181&lt;/soapenv:Envelope&gt;
182 List&lt;FullCommodityType&gt; productDesc = new List&lt;FullCommodityType&gt;();
183    
184 productDesc.Add(new FullCommodityType()
185 {
186     @class = 70,
187     classSpecified = true,
188     weight = &quot;500&quot;,
189     pieces = &quot;2&quot;,
190     pieceType = PackagingType.PT,                        
191     dimensions = dim
192 });
193
194 List&lt;FullCommoditiesType&gt; products = new List&lt;FullCommoditiesType&gt;();
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.

Source https://stackoverflow.com/questions/70172613

QUESTION

Creating Frontend-Backend connection through Mule ESB

Asked 2021-Dec-16 at 13:52

I 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:52

If 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.

Source https://stackoverflow.com/questions/70379682

QUESTION

Quickbooks Web Connector &quot;Response is not well-formed XML&quot; error

Asked 2021-Nov-18 at 00:42

We 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: &lt;Response is not well-formed XML.&gt;. 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:&lt;productVersion=&quot;2.2.0.71&quot;&gt;
1220211117.18:47:20 UTC   : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: &lt;Response is not well-formed XML.&gt;. 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:&lt;userName=&quot;scsc_qb&quot;&gt;&lt;password=&lt;MaskedForSecurity&gt;
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: &lt;Response is not well-formed XML.&gt;. 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:&lt;productVersion=&quot;2.2.0.71&quot;&gt;
1220211117.18:47:20 UTC   : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: &lt;Response is not well-formed XML.&gt;. 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:&lt;userName=&quot;scsc_qb&quot;&gt;&lt;password=&lt;MaskedForSecurity&gt;
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] =&gt; 
21    [qbwc_min_version] =&gt; 
22    [qbwc_wait_before_next_update] =&gt; 
23    [qbwc_min_run_every_n_seconds] =&gt; 
24    [qbwc_version_warning_message] =&gt; 
25    [qbwc_version_error_message] =&gt; 
26    [qbwc_interactive_url] =&gt; 
27    [autoadd_missing_requestid] =&gt; 1
28    [check_valid_requestid] =&gt; 1
29    [server_version] =&gt; PHP QuickBooks SOAP Server v3.0 at /quickbooks/qbwc_integrator.php?legal_entity=scs_consulting
30    [authenticate] =&gt; 
31    [authenticate_dsn] =&gt; 
32    [map_application_identifiers] =&gt; 1
33    [allow_remote_addr] =&gt; Array
34        (
35        )
36
37    [deny_remote_addr] =&gt; Array
38        (
39        )
40
41    [convert_unix_newlines] =&gt; 1
42    [deny_concurrent_logins] =&gt; 
43    [deny_concurrent_timeout] =&gt; 60
44    [deny_reallyfast_logins] =&gt; 
45    [deny_reallyfast_timeout] =&gt; 600
46    [masking] =&gt; 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: &quot;http://developer.intuit.com/serverVersion&quot;
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: &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;&lt;soap:Body&gt;&lt;serverVersion xmlns=&quot;http://developer.intuit.com/&quot; /&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
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: &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
80            &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; 
81             xmlns:ns1=&quot;http://developer.intuit.com/&quot;&gt;
82                &lt;SOAP-ENV:Body&gt;&lt;ns1:serverVersionResponse&gt;&lt;ns1:serverVersionResult&gt;PHP QuickBooks SOAP Server v3.0 at /quickbooks/qbwc_integrator.php?legal_entity=scs_consulting&lt;/ns1:serverVersionResult&gt;&lt;/ns1:serverVersionResponse&gt;
83            &lt;/SOAP-ENV:Body&gt;
84            &lt;/SOAP-ENV:Envelope&gt;
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:42

SOLVED - 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!

Source https://stackoverflow.com/questions/70010614

QUESTION

PowerShell - how to escape {} in JSON string for a REST call

Asked 2021-Oct-20 at 15:00

I'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 = @&quot;
2&lt;html&gt;
3    &lt;style type=&quot;text/css&quot;&gt;.LetterList {font-family:&quot;arial&quot;}&lt;/style&gt;
4    &lt;body&gt;
5        To [firstname]:
6        This is a normal body with special JSON characters. 
7    &lt;/body&gt;
8&lt;/html&gt;
9&quot;@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace(&quot;{&quot;,&quot;\{&quot;).Replace(&quot;}&quot;,&quot;\}&quot;)
13
14Write-Host &quot;After RegEx Fix&quot;
15Write-Host $HtmlFromFileFixed 
16
17$templateID = &quot;Test_Temp7&quot;
18
19
20$body = @&quot;
21{   &quot;uuid&quot;: &quot;$templateID&quot;,
22    &quot;subject&quot;: &quot;My Email Subject&quot;,
23    &quot;body&quot;: &quot;$HtmlFromFileFixed&quot;
24}
25&quot;@
26
27# This also tests if our JSON is &quot;well-formed&quot;, 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        = &quot;$body&quot;
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 = @&quot;
2&lt;html&gt;
3    &lt;style type=&quot;text/css&quot;&gt;.LetterList {font-family:&quot;arial&quot;}&lt;/style&gt;
4    &lt;body&gt;
5        To [firstname]:
6        This is a normal body with special JSON characters. 
7    &lt;/body&gt;
8&lt;/html&gt;
9&quot;@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace(&quot;{&quot;,&quot;\{&quot;).Replace(&quot;}&quot;,&quot;\}&quot;)
13
14Write-Host &quot;After RegEx Fix&quot;
15Write-Host $HtmlFromFileFixed 
16
17$templateID = &quot;Test_Temp7&quot;
18
19
20$body = @&quot;
21{   &quot;uuid&quot;: &quot;$templateID&quot;,
22    &quot;subject&quot;: &quot;My Email Subject&quot;,
23    &quot;body&quot;: &quot;$HtmlFromFileFixed&quot;
24}
25&quot;@
26
27# This also tests if our JSON is &quot;well-formed&quot;, 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        = &quot;$body&quot;
37    ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): {   &quot;uuid&quot;: &quot;FEMAImport_Home_Test_Temp7&quot;,
42    &quot;subject&quot;: &quot;SBA Disaster Loan Assistance TestText&quot;,
43    &quot;body&quot;: &quot;&lt;html&gt;    &lt;style type=&quot;text/css&quot;&gt;.sbaLetterList \{font-family:&quot;arial&quot;\}&lt;/style&gt;&lt;body&gt;    This is a 
44normal body with special JSON characters. &lt;/body&gt;&lt;/html&gt;&quot;
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 = @&quot;
2&lt;html&gt;
3    &lt;style type=&quot;text/css&quot;&gt;.LetterList {font-family:&quot;arial&quot;}&lt;/style&gt;
4    &lt;body&gt;
5        To [firstname]:
6        This is a normal body with special JSON characters. 
7    &lt;/body&gt;
8&lt;/html&gt;
9&quot;@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace(&quot;{&quot;,&quot;\{&quot;).Replace(&quot;}&quot;,&quot;\}&quot;)
13
14Write-Host &quot;After RegEx Fix&quot;
15Write-Host $HtmlFromFileFixed 
16
17$templateID = &quot;Test_Temp7&quot;
18
19
20$body = @&quot;
21{   &quot;uuid&quot;: &quot;$templateID&quot;,
22    &quot;subject&quot;: &quot;My Email Subject&quot;,
23    &quot;body&quot;: &quot;$HtmlFromFileFixed&quot;
24}
25&quot;@
26
27# This also tests if our JSON is &quot;well-formed&quot;, 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        = &quot;$body&quot;
37    ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): {   &quot;uuid&quot;: &quot;FEMAImport_Home_Test_Temp7&quot;,
42    &quot;subject&quot;: &quot;SBA Disaster Loan Assistance TestText&quot;,
43    &quot;body&quot;: &quot;&lt;html&gt;    &lt;style type=&quot;text/css&quot;&gt;.sbaLetterList \{font-family:&quot;arial&quot;\}&lt;/style&gt;&lt;body&gt;    This is a 
44normal body with special JSON characters. &lt;/body&gt;&lt;/html&gt;&quot;
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 = &quot;$PSScriptRoot\Emailbody_Home.html&quot; 
52#$HtmlBodyFilename = &quot;$PSScriptRoot\Emailbody_Home_SimpleTest.html&quot; 
53#$HtmlBodyFilename = &quot;$PSScriptRoot\Emailbody_Home_SimpleTestWithBraces.html&quot; 
54    $HtmlFromFile = Get-Content $HtmlBodyFilename -Raw   #the -Raw option gets a string instead of an array of lins 
55    $HtmlFromFileStripped = $HtmlFromFile.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
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:00

Let Powershell do all the work for you and don't build the JSON string yourself, use an object:

1$HtmlFromFile2 = @&quot;
2&lt;html&gt;
3    &lt;style type=&quot;text/css&quot;&gt;.LetterList {font-family:&quot;arial&quot;}&lt;/style&gt;
4    &lt;body&gt;
5        To [firstname]:
6        This is a normal body with special JSON characters. 
7    &lt;/body&gt;
8&lt;/html&gt;
9&quot;@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace(&quot;{&quot;,&quot;\{&quot;).Replace(&quot;}&quot;,&quot;\}&quot;)
13
14Write-Host &quot;After RegEx Fix&quot;
15Write-Host $HtmlFromFileFixed 
16
17$templateID = &quot;Test_Temp7&quot;
18
19
20$body = @&quot;
21{   &quot;uuid&quot;: &quot;$templateID&quot;,
22    &quot;subject&quot;: &quot;My Email Subject&quot;,
23    &quot;body&quot;: &quot;$HtmlFromFileFixed&quot;
24}
25&quot;@
26
27# This also tests if our JSON is &quot;well-formed&quot;, 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        = &quot;$body&quot;
37    ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): {   &quot;uuid&quot;: &quot;FEMAImport_Home_Test_Temp7&quot;,
42    &quot;subject&quot;: &quot;SBA Disaster Loan Assistance TestText&quot;,
43    &quot;body&quot;: &quot;&lt;html&gt;    &lt;style type=&quot;text/css&quot;&gt;.sbaLetterList \{font-family:&quot;arial&quot;\}&lt;/style&gt;&lt;body&gt;    This is a 
44normal body with special JSON characters. &lt;/body&gt;&lt;/html&gt;&quot;
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 = &quot;$PSScriptRoot\Emailbody_Home.html&quot; 
52#$HtmlBodyFilename = &quot;$PSScriptRoot\Emailbody_Home_SimpleTest.html&quot; 
53#$HtmlBodyFilename = &quot;$PSScriptRoot\Emailbody_Home_SimpleTestWithBraces.html&quot; 
54    $HtmlFromFile = Get-Content $HtmlBodyFilename -Raw   #the -Raw option gets a string instead of an array of lins 
55    $HtmlFromFileStripped = $HtmlFromFile.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
56$body = ConvertTo-Json @{
57    uuid = $templateID
58    subject = &quot;My Email Subject&quot;
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 = @&quot;
2&lt;html&gt;
3    &lt;style type=&quot;text/css&quot;&gt;.LetterList {font-family:&quot;arial&quot;}&lt;/style&gt;
4    &lt;body&gt;
5        To [firstname]:
6        This is a normal body with special JSON characters. 
7    &lt;/body&gt;
8&lt;/html&gt;
9&quot;@
10$HtmlFromFile2Stripped = $HtmlFromFile2.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
11#$HtmlFromFileFixed = % { [System.Text.RegularExpressions.Regex]::Unescape($HtmlFromFile2Stripped) }
12$HtmlFromFileFixed = $HtmlFromFile2Stripped.Replace(&quot;{&quot;,&quot;\{&quot;).Replace(&quot;}&quot;,&quot;\}&quot;)
13
14Write-Host &quot;After RegEx Fix&quot;
15Write-Host $HtmlFromFileFixed 
16
17$templateID = &quot;Test_Temp7&quot;
18
19
20$body = @&quot;
21{   &quot;uuid&quot;: &quot;$templateID&quot;,
22    &quot;subject&quot;: &quot;My Email Subject&quot;,
23    &quot;body&quot;: &quot;$HtmlFromFileFixed&quot;
24}
25&quot;@
26
27# This also tests if our JSON is &quot;well-formed&quot;, 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        = &quot;$body&quot;
37    ContentType = 'application/json'
38}
39
40#Invoke-RestMethod @params
41ConvertFrom-Json : Invalid object passed in, ':' or '}' expected. (137): {   &quot;uuid&quot;: &quot;FEMAImport_Home_Test_Temp7&quot;,
42    &quot;subject&quot;: &quot;SBA Disaster Loan Assistance TestText&quot;,
43    &quot;body&quot;: &quot;&lt;html&gt;    &lt;style type=&quot;text/css&quot;&gt;.sbaLetterList \{font-family:&quot;arial&quot;\}&lt;/style&gt;&lt;body&gt;    This is a 
44normal body with special JSON characters. &lt;/body&gt;&lt;/html&gt;&quot;
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 = &quot;$PSScriptRoot\Emailbody_Home.html&quot; 
52#$HtmlBodyFilename = &quot;$PSScriptRoot\Emailbody_Home_SimpleTest.html&quot; 
53#$HtmlBodyFilename = &quot;$PSScriptRoot\Emailbody_Home_SimpleTestWithBraces.html&quot; 
54    $HtmlFromFile = Get-Content $HtmlBodyFilename -Raw   #the -Raw option gets a string instead of an array of lins 
55    $HtmlFromFileStripped = $HtmlFromFile.Replace(&quot;`r&quot;, &quot;&quot;).Replace(&quot;`n&quot;, &quot;&quot;).Replace(&quot;`t&quot;,&quot;&quot;) 
56$body = ConvertTo-Json @{
57    uuid = $templateID
58    subject = &quot;My Email Subject&quot;
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 = &quot;My Email Subject&quot;
68        body = Get-Content $HtmlBodyFilename -Raw
69    }
70    ContentType = 'application/json'
71}
72

Source https://stackoverflow.com/questions/69647261

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

Share this Page

share link

Get latest updates on SOAP