I am a new comer to soap protocol, so I want to find a perl module to produce soap fragments so that I can learn how to construct a soap fragment with it, SOAP::Lite is an excellent module for soap, but I can not find tutorials on how to output the soap fragment to files or stdout, so any tips?
regards.
use strictures;
use SOAP::Lite qw();
my $soap_body = SOAP::Data->name('foo' => \SOAP::Data->value(SOAP::Data->name('bar' => '123')));
print SOAP::Serializer->envelope(freeform => $soap_body);
$ perl -C /tmp/soap.pl | xmllint -format -
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<foo>
<bar xsi:type="xsd:int">123</bar>
</foo>
</soap:Body>
</soap:Envelope>
For experimentation tasks like this, it is usually better to use a REPL. It gives you quicker turn-around because you see the results immediately after entering an expression.
Related
I'm using Azure Logic App to transform a CSV file to XML, everything was initially set up in BizTalk first to generate the relevant XSDs and XSL which worked perfectly fine. But when I use Azure Logic App the output XML file is all in one line even though I made sure it has indent="yes" in the XSL file.
I know I can use notepad++ to pretty print the result and save the file, but surely there's a way to automatically do that in Logic App?
For those interested, I've found a setting within the Logic App, simply select Apply XSLT output attributes and that's it, no validation needed either!
I manage to get indentation when using XSLT 3.0 with e.g. the stylesheet/map doing
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<xsl:next-match/>
<xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
then a request of e.g.
<root><item>a</item><item>b</item></root>
is transformed to the output
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>a</item>
<item>b</item>
</root>
<!--Run with SAXON HE 9.8.0.8 -->
I don't know how they run the XSLT 1.0 processor to ignore the xsl:output settings, seems a flaw or quirk in the pipeline.
I am currently using a crossplatform c++ project (windows+linux) which will soon need an external xsd validator.
My plan is to:
either find a c++ library which does xsd validation (possibly a complex task)
or an existing tool which I could just launch as an external process (easier I believe; Xerces could be an option?)
I have a deep hierarchy of xsd files, so I need a solid tool for the job.
My question: I need some suggestions about some easy-to-integrate-yet-production-ready-solution.
My take for now is to use Xerces, the java version and just call it in a separate process.
Probably I need to wrap Xerces, since it seems to not allow xsd validation in the command line, directly, e.g. https://github.com/ndw/xjparse.
Thanks
You could use xmllint with the --schema option:
xmllint --noout --schema test.xsd test.xml
test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="info" type="xs:string"/>
</xs:schema>
test.xml
<?xml version="1.0"?>
<info>abc</info>
I've been shifting between node-soap and strong-soap since they both generate different payloads and work similarly (All I have to do is change the require path and I can shift between strong-soap and node-soap without changing existing code)
However, when I'm using node-soap, I't really does generate these weird payloads.
Here's an exmaple
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:i0="http://services.redacted.com/Contracts" xmlns:msb="http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:tns="http://services.redacted.com/Contracts" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<stns:SecurityToken xmlns:stns="http://services.redacted.com/Security">
<ServiceKey>123</ServiceKey>
<UserId>123</UserId>
<Username>123</Username>
<Password>123</Password>
</stns:SecurityToken>
</soap:Header>
<soap:Body>
<DataService_GetProfiles_InputMessage />
</soap:Body>
</soap:Envelope>
So it's all fine, except the method I'm trying to invoke is called: GetProfiles not DataService_GetProfiles_InputMessage and subsequently the service I'm trying to communicate with doesn't recognise the method I'm trying to invoke.
What does work (And what strong-soap generates)
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:i0="http://services.redacted.com/Contracts" xmlns:msb="http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:tns="http://services.redacted.com/Contracts" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<stns:SecurityToken xmlns:stns="http://services.redacted.com/Security">
<ServiceKey>123</ServiceKey>
<UserId>123</UserId>
<Username>123</Username>
<Password>123</Password>
</stns:SecurityToken>
</soap:Header>
<soap:Body>
<GetProfiles />
</soap:Body>
</soap:Envelope>
Now that makes sense. However, due to other constraints we can't stick to strong-soap.
Is there a way I can override the requested payload? Is there a reason It's generating this weird XML?
My Code:
this.dataClientConnection.DataService.BasicHttpBinding_DataService.GetProfiles()
The solution was the following:
Documentation LIST ITEM 5
You will however override the entire document you're sending.
I did not figure out a way to override certain nodes.
I am doing a xml to object conversion in mule using jaxb but, whenever i am using xml tag i am getting this error-
org.xml.sax.SAXParseException - The processing instruction target matching "[xX][mM][lL]" is not allowed.
following is my input message-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.standalone.com/">
<soapenv:Header/>
<soapenv:Body>
<test:getResultString>
<!--Optional:-->
<inputXml>
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<autoBean>
<autoID>1</autoID>
<country>sdf</country>
<model>sdf</model>
<year>sf</year>
</autoBean>
]]>
</inputXml>
</test:getResultString>
</soapenv:Body>
</soapenv:Envelope>
if i remove "" transformation is working fine, but it is mendatory for me to use the .
I have resolved this by removing the white space between wsdl element and cdata as follows,
compare it with the above request message in question
<inputXml><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<autoBean>
<autoID>4</autoID>
<country>sdf</country>
<model>sdf</model>
<year>2013-01-01</year>
</autoBean>
]]>
What is wrong with this SOAP request? I keep on getting 400 bad request error.
<S:Body>
<GetTermSets xmlns="http://schemas.microsoft.com/sharepoint/taxonomy/soap/">
<sharedServiceIds>
<termStoreIds>
<termStoreId>27a0a321-083f-4688-8b6e-d86b7ab42de9</termStoreId>
</termStoreIds>
</sharedServiceIds>
<termSetIds>
<termSetIds><termSetId>cb1b9444-159d-48c3-b9a7-19ebd612e796</termSetId></termSetIds>
</termSetIds>
<lcid>1033</lcid>
<clientTimeStamps>
<timeStamps><timeStamp>2304823424</timeStamp></timeStamps>
</clientTimeStamps>
<clientVersions><versions><version>1</version></versions></clientVersions>
</GetTermSets>
</S:Body>
I was struggling with this for a long time as well, and had extrapolated the same request from all the examples that I could find online.
But I managed to get it working by looking up "MS-EMMWS" (my working example below)
MS-EMMWS - Protocol Examples
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetTermSets xmlns="http://schemas.microsoft.com/sharepoint/taxonomy/soap/">
<sharedServiceIds><sspIds><sspId>0d18c636-63d4-452b-b094-6de97ee5159d</sspId></sspIds>
</sharedServiceIds><termSetIds><termSetIds><termSetId>48508451-17d5-4bdb-b1c9-7f096f680352</termSetId></termSetIds></termSetIds><lcid>1033</lcid>
<clientTimeStamps><dateTimes><dateTime>1900-01-01T00:00:00</dateTime></dateTimes></clientTimeStamps>
<clientVersions><versions><version>0</version></versions></clientVersions></GetTermSets>
</soap:Body>
</soap:Envelope>