How to extract SOAP response using pysimplesoap? - pysimplesoap

I am new on using pysimplesoap. I am succeed using pysimplesoap to generate a soap request to a SOAP server, and the soap server is responded correctly, however, I do not know how to extract the information returned.
This is my code on pysimplesoap for the request
> from pysimplesoap.client import SoapClient
> client = SoapClient(location="http://192.168.206.111:8998/axis2/services/SecurityService", action="", namespace="http://www.labtest.com/Security", ns="ns3")
> response = client.call("login", ("ns3:loginName", "administrator"), ("ns3:password", "admin"))
The SOAP response is in below format.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<n:loginResponse
xmlns:n="http://www.labtest.com/Security"
xmlns:n0="http://www.labtest.com/Types">
<n:errorCode>
<n0:hasError>
false
</n0:hasError>
<n0:status>
STATUS_SUCCESS
</n0:status>
</n:errorCode>
<n:authorizationToken>
<n0:token>
6430303938366138316265646532313138623866353235343030346130653330
</n0:token>
<n0:securityPrivileges>
<n0:values>
<n0:securityAttribute>
SUPER_USER_ACCESS
</n0:securityAttribute>
<n0:accessRights>
<n0:values>
FULL_CONTROL
</n0:values>
</n0:accessRights>
</n0:values>
</n0:securityPrivileges>
</n:authorizationToken>
</n:loginResponse>
</soapenv:Body>
</soapenv:Envelope>
I tried to use the print response or print (response), but nothing show up.

The response object is a pysimplesoap.client.SimpleXMLElement.
Behind the hood, a print(response) will call its __str__() method, the choice have been made, for pysimplesoap that `__str__() returns the text content of the node (if any), if your node contains no text content, like :
<MySoapResponse>
<child tag attr="value />
</MySoapResponse>
… then, __str__() will return nothing, and so do printing.
Alternatively, you may want to
navigate the XML tree of your answer by using SimpleXMLElement methods :
children() to grab childrens list
tag['attr'] (dict notation) to access attributes of an XML tag
tag.get_name() to get a tag name ;
inspect the full answer as a string (including Soap headers) as string calling repr(response), but it's more for debugging purposes.
See also the basic client documentation online.

Related

WinHttpRequest: Send method

I'm trying to pass parameters in the request body, the documentation says :
The request to be sent was defined in a prior call to the Open method. The calling application can provide data to be sent to the server through the Body parameter. If the HTTP verb of the object's Open is "GET", this method sends the request without Body, even if it is provided by the calling application.
So, I need to use POST with body. But when I use use POST with body I have error "Bad Request: message text is empty" and when I use GET with body result is ok. Why?
My code:
WinHttp = NEW COMObject("WinHttp.WinHttpRequest.5.1");
WinHttp.Open("GET", "http://api.telegram.org/botbotname/sendMessage", 0);
WinHttp.setRequestHeader("Content-type", "application/json");
JSONWr = New JSONWriter();
JSONWr.ValidateStructure = False;
JSONParams = New JSONWriterSettings( , Chars.Tab);
JSONWr.SetString(JSONParams);
JSONWr.WriteStartObject();
JSONWr.WritePropertyName("chat_id");
JSONWr.WriteValue(UserId);
JSONWr.WritePropertyName("text");
JSONWr.WriteValue(Text);
JSONWr.WriteEndObject();
JSONString = JSONWr.Close();
WinHttp.Send(JSONString);
work, but how? And why the same with POST doesn`t work?

How to get the raw response as a String in Spring webflux?

return webClient//
.post()//
.uri(whatever.com)
.header("Authorization", "Bearer " + authToken)//
.header("userId", CLIENT_ID)//
.header("clientRequestId", requestId)//
.bodyValue(bodyValue())//
.retrieve()//
.bodyToMono(Responseclass.class)//
.block();
The above is working. But let's say I'm debugging and I just want to dump the raw response json into a String. How would I do that? toString() after retrieve doesn't work, and bodyToMono(String.class) didn't seem to work either. Either way it just printed the default toString value of the address of the pointer.
With Spring Webflux WebClient you can get response as String like this:
WebClient client = WebClient.create("http://someurl.de/something");
String responseBody = client.get().retrieve().toEntity(String.class)
.block().getBody();
In my German blog I wrote an article about using WebClient, there you will find more details around the code snippet above:
https://agile-coding.blogspot.com/2021/01/reactive-webclient.html

VBA MSSOAP.SoapClient30 error: Incorrect number of parameters supplied for SOAP request HRESULT=0x80070057

update: so I've figured I need to somehow submit a complex type at method parameter - how do I do this with VBA?
This is my first time coding VBA and I will appreciate any possible pointers at how I can fix the problem. Basically, I've written a little soap service and it works fine - I test it with SoapUI - so I guess other application should be able to consume it.
The WSDL the service generates is here. Perhaps, it is not too friendly for consuming by VBScript SOAPClient - any points in that direction will help a lot.
I'm trying to put a bit of code together that actually uses it (VBScript below) - I've built it on top of an example I found while googling. It generates the following error:
Incorrect number of parameters supplied for SOAP request HRESULT=0x80070057
Module Module1
Dim WSDLFileName As String
Dim base64attachment As String
Dim attachment_filename As String
Dim summary As String
Dim SoapClient
Dim res
Sub Main()
WSDLFileName = "http://localhost:7777/?wsdl"
base64attachment = "UG9ydG1hbiBpcyBwb3J0Zm9saW8gbWFuYWdlbWVudCBzb2Z0d2FyZSB0byBoZWxwIFBNTyBrZWV"
attachment_filename = "test_file.txt"
summary = "test issue with summary"
SoapClient = CreateObject("MSSOAP.SoapClient30")
SoapClient.MSSoapInit(WSDLFileName)
res = SoapClient.CreateJiraIssueWithBase64Attachment(summary, base64attachment, attachment_filename)
Console.Out.WriteLine(res)
End Sub
End Module
Any pointers will help, I'm lost here.
I'm expecting it should create a response like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="open.JiraAdapter">
<soapenv:Header/>
<soapenv:Body>
<open:CreateJiraIssueWithBase64Attachment>
<open:summary>some summary</open:summary>
<open:base64attachment>BASE64CODEDFILE</open:base64attachment>
<open:attachment_filename>NAME of the file attached</open:attachment_filename>
</open:CreateJiraIssueWithBase64Attachment>
</soapenv:Body>
</soapenv:Envelope>
Your service response contains complex type object.
<xs:element name="CreateJiraIssueWithBase64AttachmentResult" type="s0:Status" minOccurs="0" nillable="true"/>
To be able to use complex types you need to use "MSSOAP.SoapSerializer30" to create request and "MSSOAP.SoapReader30" for reading response.
SOAP UI can helps you to see the correct request structure (tags, namespaces and actions).
I think it something like that
Connector = CreateObject("MSSOAP.HttpConnector30")
Connector.Property("EndPointURL") = "url"
Connector.Property("UseSSL") = True
Connector.Connect
Connector.Property("SoapAction") = "CreateJiraIssueWithBase64Attachment"
Connector.BeginMessage
Serializer = CreateObject("MSSOAP.SoapSerializer30")
Serializer.Init(Connector.InputStream)
Serializer.StartEnvelope
Serializer.StartBody
Serializer.StartElement("CreateJiraIssueWithBase64Attachment";"open.jiraAdapter.test")
Serializer.StartElement("summary";"open.jiraAdapter.test")
Serializer.WriteString("another test issue for JUR")
Serializer.EndElement
Serializer.StartElement("base64attachment";"open.jiraAdapter.test")
Serializer.WriteString("Y29kZTogaHR0cDovL3Bhc3RlYmluLmNvbS9EbUx3N0oycQ0KeG1sOiBodHRwOi8vcGFzdGViaW4uY29tLzE3Q2MxVjJM")
Serializer.EndElement
Serializer.StartElement("attachment_filename";"open.jiraAdapter.test")
Serializer.WriteString("readme.txt")
Serializer.EndElement
Serializer.EndElement
Serializer.EndBody
Serializer.EndEnvelope
Connector.EndMessage
Reader = CreateObject("MSSOAP.SoapReader30")
Reader.Load(Connector.OutputStream)
/// Reader.Body.xml - response
Hope this help you.

Urlfetch blobs multipart/m

I am trying to use UlrFetch to submit CSV data to Zoho reports. I am using the following code:
function doImport(tabla,file) {
var url="https://reportsapi.zoho.com/api/xxxxxxxx/yyyyyyyyyyy/"+tabla;
var ticket="zzzzzzzzzzzzzzzz" ;//getTicket();
url=url + "?ZOHO_ACTION=IMPORT&ZOHO_OUTPUT_FORMAT=XML&ZOHO_ERROR_FORMAT=json&ZOHO_API_VERSION=1.0"
var params={"ZOHO_API_KEY":"vvvvvvvvvvvvvvvvvvvvvv"
,"ticket":ticket
,"ZOHO_FILE":file
,"ZOHO_IMPORT_TYPE":"APPEND"
,"ZOHO_ON_IMPORT_ERROR":"ABORT"
,"ZOHO_AUTO_IDENTIFY":"true"
,"ZOHO_CREATE_TABLE":"false"
,"ZOHO_DATE_FORMAT":"dd-MM-YYYY"
,"ZOHO_DELIMITER":"0"
};
var options =
{
"method" : "post",
"payload" : params,
"contentType": "multipart/form-data"
};
var response=UrlFetchApp.fetch(url, options);
var tableDataString=response.getContentText();
expireTicket(ticket);
Logger.log(tableDataString);
return tableDataString;
}
However, the data is not submitted in correct multiform format (getting error 500 status). This issue backtracks to early 2011. Please, one or two examples of how to submit blob files in multipart/form-data format would be welcome.
Thanks
For payload, you are passing it as an Object, which looks correct. This will be interpreted as an HTTP form (which you want).
To fix your script, try the following:
Make sure the value you're using for ZOHO_FILE is a Blob. This makes sure the HTTP form will automatically be sent with:Content-Type: multipart/form-data; boundary=[automatically determined]
Do not specify contentType for the HTTP POST. This allows UrlFetchApp to automatically use its own contentType value, which includes the boundary field. (Minor detail: It's ok to still specify contentType on the Blob itself, just not the overall post request. This allows specifying the contentType of each Blob within the post, if that interests you.)
UrlFetchApp will use multipart/form-data encoding automatically if you pass a Blob as a payload value. You may need to use:
"ZOHO_FILE": file.getBlob()

Passing a string param to a RESTful service during POST action

I am having a RESTful service with the following method:
[WebInvoke]
string GetDataFromStringAsString(string xmlString);
My client call to the method is as below:
var client = new RestClient();
client.BaseUrl = serviceBaseUrl;
var request = new RestRequest(method){RequestFormat = DataFormat.Xml};
request.Resource = resourceUrl;
request.AddParameter("text/xml", requestBody,
ParameterType.RequestBody);
var response = client.Execute(request);
Let us take a string to post as "Hello World".
Now the string that i post to the above method gives me a 400 Bad
request. In order to get it working i had to wrap the above string in
a element as shown below:
<string xmlns="http://schemas.microsoft.com/2003/10/
Serialization/">Hello World</string>
Now when i post the above string i get a success response back from
the server.
Why is that i have to manually wrap the string to make it work. Is
there a way that i can achieve to post a string without doing the
above manually.
The only other way that I am aware of is to use stream as your input parameter. e.g.
[WebInvoke]
string GetDataFromStringAsString(stream xmlString);
The problem with .Net 4 WCF REST is that fundamentally WCF only knows how to pass two types of info, either XML or a stream of bytes. Personally, I would use WCF Web API instead of the standard WCF REST library because you are going run into lots more of these kinds of issues.