Parse soap msg with gSOAP - c++

I have following example xml message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<to>...</to>
<from>...</from>
<id>..</id>
<relatesTo>...</relatesTo>
<action>...</action>
<version>...</version>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<customComplexElement>
<a>a_v</a>
<b>b_v</b>
<c>c_v</c>
<d>d_v</d>
<e>e_v</e>
<f>f_v</f>
</customComplexElement>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
From which I have generated a xsd file with use of one of online tools:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="id" type="xs:string"/>
<xs:element name="relatesTo" type="xs:string"/>
<xs:element name="action" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
<xs:element name="customComplexElement">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="a"/>
<xs:element type="xs:string" name="b"/>
<xs:element type="xs:string" name="c"/>
<xs:element type="xs:string" name="d"/>
<xs:element type="xs:string" name="e"/>
<xs:element type="xs:string" name="f"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then I generate the appropriate header file with wsdl2h.exe and then compile it with soapcpp2.exe compiler.
Then I try to read xml file with a function soap_read_customComplexElement() and all I get is SOAP_TAG_MISMATCH. This method seems to work if I get rid of all the soap stuff the message but I wonder if there are some functions in gSOAP to parse soap envelope, header and body?

I've had same problem. But i've just fixed it.
So, in my case i use this line of code.
struct soap *soap = soap_new1(SOAP_C_UTFSTRING | SOAP_XML_IGNORENS | SOAP_XML_TREE);
The key paramter is SOAP_XML_IGNORENS. This parameter ignore namespaces.
SOAP_XML_IGNORENS in: ignores the use of XML namespaces in input
The root of this problem is that you don't declare namespaces in your body content. That why gSoap don't know how to convert this xml.
This wouldn't be converted, because gSoap don't know what is ns4:
<ns4:ParseKeywords><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>
But if i declare namespace it will be converted
<ns4:ParseKeywords xmlns:ns4="com.idurdyev.idcommerce:ParseKeywords:1.0"><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>

Related

Generate wsdl from xsd using common property from common xsd file

I have to generate separate wsdl for separate client.
entry.xsd -> entry.wsdl
migration.xsd -> migration.wsdl
I am using spring boot contract frist approach for generating wsdl from xsd definition. Problem is type are same for both xsd fiels like: credential, so I want to create a common xsd file and include/import in both xsd so can reduce redundant code.
like common.xsd -> entry.xsd, migration.xsd
but getting exception or soap client giving invalid error message.
Any help, how to generate wsdl from two xsd where one is base xsd file?
It's giving, failed to update interface. InvalidFormatException from SOAP Client.
entry.sxd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.test.com/idms-ws"
targetNamespace="http://www.test.com/idms-ws"
elementFormDefault="qualified">
<xs:include schemaLocation="common-element.xsd"></xs:include>
<xs:element name="updateMigrationStatusRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="credential" type="tns:credential" minOccurs="0"/>
<xs:element name="referenceNo" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
common-element.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="credential">
<xs:sequence>
<xs:element name="loginName" type="xs:string" minOccurs="0"/>
<xs:element name="password" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Transformation inside while loop- BPEL 10g

Requirement is read data from file and invoke webservice. Target webservice can handle one payload at a time but there will be multiple payload in source.
So am using while loop to process payload one by one.
Issue: In target service EarningTypeInclusion is optional element, so in source some payload this element will be present and in some payload this option element will not be present.
<thresholdRequestInterface xmlns:xs="http://www.sample.com/ns/LMSReferrals">
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
</thresholdRequest>
</thresholdRequestInterface>
If am using assign activity, then selection failure fault will come when optional elements are not present in source payload. We are using BPEL 10g, no option in assign activity to supress selection failure fault.
So decided to use transformation inside while loop .
logic used
Read from file
assign Loop counter=1
Count of payload(read from file)
While loop counter<= Count of payload
pass loop counter param value to transform
transform source i.e thresholdRequest[loopcounter] to target
Invoke target web service
increment loop counter
end loop;
Problem is same data is getting trsnformed.
In the below example, referral 11 data is loading 3 times. I have checked conter value, its getting incremented but inside transformation same values are getting transformed.
<thresholdRequestInterface xmlns:xs="http://www.sample.com/ns/LMSReferrals">
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
<thresholdRequest>
<Referral>12</Referral>
<thresholdValue>100</thresholdValue>
</thresholdRequest>
<thresholdRequest>
<Referral>13</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
</thresholdRequestInterface>
Source
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://www.sample.com/ns/LMSReferrals" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.sample.com/ns/LMSReferrals" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="thresholdRequestInterface">
<xs:complexType>
<xs:sequence>
<xs:element name="thresholdRequest" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Referral" type="xs:string"/>
<xs:element name="thresholdValue" type="xs:int"/>
<xs:element name="EarningTypeInclusion" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="earningType" type="xs:stirng" />
<xs:element name="ProvisionId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please find the schema structure for source and target
Target
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://www.sample.com/ns/LMSReferrals" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.sample.com/ns/LMSReferrals" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="thresholdRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Referral" type="xs:string"/>
<xs:element name="thresholdValue" type="xs:int"/>
<xs:element name="EarningTypeInclusion" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="earningType" type="xs:stirng" />
<xs:element name="ProvisionId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please note schema validation is enabled at target webservice.
Is there a specific reason that you are using Transform.Try using ora:getElement('/thresholdRequestInterface /thresholdRequest',bpws:getVariable(loopCounter))

Conflict between 2 .xsd files of the same SOAP Service

I have a webservice, and I'm trying to write a client for it. But when I try to add a "Web Service Client" in Netbeans IDE, wsimport utility cannot parse the .wsdl. The reason is "The class serviceCompany is already in use".
I began to analyze the wsdl file, and noticed that there are 2 .xsd files related to the WS.
<types>
<xsd:schema>
<xsd:import namespace="http://services.ws.x.net/" schemaLocation="https://test.x:443/PaymentWS/PaymentWS?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://commonws.ws.x.net/" schemaLocation="https://test.x:443/PaymentWS/PaymentWS?xsd=2"/>
</xsd:schema>
</types>
And I have a complex type named "ServiceCompany" inside of each .xsd files.
inside ?xsd=1:
<xs:complexType name="serviceCompany">
<xs:sequence>
<xs:element name="bankAccount" type="tns:iban"/>
<xs:element name="code" type="tns:companyCode"/>
<xs:element name="description" type="tns:stringMax32"/>
<xs:element name="taxNumber" type="tns:taxNumber"/>
</xs:sequence>
</xs:complexType>
inside ?xsd=2:
<xs:complexType name="serviceCompany">
<xs:sequence>
<xs:element name="code" type="cmn:companyCode"/>
<xs:element name="description" type="cmn:stringMax32"/>
<xs:element name="manualPaymentReceiverCode" type="cmn:companyCode" minOccurs="0"/>
<xs:element name="scCategoryList" type="cmn:stringMax32" maxOccurs="unbounded"/>
<xs:element name="status" type="cmn:objectStatus"/>
<xs:element name="branchList" type="tns:serviceCompanyBranch" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
The namespaces of there .xsd files are different, why wsimport cannot import the wsdl? How can I solve this problem?
Thanks in advance!

Primary and foreign keys in xml schema

I am trying to insert primary and foreign keys in XSD schema file below :-
Primary key is StudentID and Foreign Keys are courseID, AddressID, GradeID.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Student">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Dateborn" type="xs:date"/>
<xs:element name="Gender" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
However above code is not working in my setup please help me in tracing the issue,
In general you would need to put more details in a question... So this should be enough to understand what else you might need to define, and how. I'll tackle what's needed to understand how to define a primary key/foreign key by illustrating an assumed student/address relationship.
First you need to define a context where these constraints hold true. In my modified XSD, I call it the "World".
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="World">
<xs:complexType>
<xs:sequence>
<xs:element ref="Student" maxOccurs="unbounded"/>
<xs:element ref="Address" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="PKStudents">
<xs:selector xpath="Student/StudentID"/>
<xs:field xpath="."/>
</xs:key>
<xs:key name="PKAddresses">
<xs:selector xpath="Address/AddressID"/>
<xs:field xpath="."/>
</xs:key>
<xs:keyref name="FKStudentToAddress" refer="PKAddresses">
<xs:selector xpath="Student/AddressID"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>
<xs:element name="Student">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Dateborn" type="xs:date"/>
<xs:element name="Gender" type="xs:string"/>
<xs:element name="StudentID" type="xs:string"/>
<xs:element name="AddressID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="AddressID" type="xs:string"/>
<xs:element name="Street" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Province" type="xs:string" minOccurs="0"/>
<xs:element name="Country" type="xs:date" minOccurs="0"/>
<xs:element name="PostalCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then an XML like this would pass or fail, depending on what you do with the values in the StudentID and AddressID fields.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<World xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Student>
<Title>Title1</Title>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Dateborn>1900-01-01</Dateborn>
<Gender>Gender1</Gender>
<StudentID>StudentID1</StudentID>
<AddressID>AddressID1</AddressID>
</Student>
<Student>
<Title>Title1</Title>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Dateborn>1900-01-01</Dateborn>
<Gender>Gender1</Gender>
<StudentID>StudentID2</StudentID>
<AddressID>AddressID1</AddressID>
</Student>
<Address>
<AddressID>AddressID1</AddressID>
<Street>Street1</Street>
<City>City1</City>
<Province>Province1</Province>
<Country>1900-01-01</Country>
<PostalCode>PostalCode1</PostalCode>
</Address>
<Address>
<AddressID>AddressID2</AddressID>
<Street>Street1</Street>
<City>City1</City>
<Province>Province1</Province>
<Country>1900-01-01</Country>
<PostalCode>PostalCode1</PostalCode>
</Address>
</World>
To finish your solution, you would need to define the Course and Grade "entities" in your "world", define the xs:key for each, similar to Student/*Address*, then add CourseID and GradeID attributes to the entities that need them, and finally, define the keyref, as above, for Entity to Grade and Entity to Course.

Testing a secured webservivce in SOAP UI

I am using AXIS2 framework for my webservices creating. Now I am secured my webservices using ramprt. Now entire requests and response will be signed and encrypted.
Now my doubt is how can i test it in SOAP UI. when I am loading wsdl file it giving me as
below.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soapenvelope"
xmlns:sam="http://sample03.policy.samples.rampart.apache.org">
<soap:Header/>
<soap:Body>
<sam:echo>
<!--Optional:-->
<sam:args0>?</sam:args0>
</sam:echo>
</soap:Body>
</soap:Envelope>
Now Ho w can i place digital certificate related data and how can i encrypt the content i want to send to axis server.
Thanks,
Narendra
the certificate data is stored in two xml Files the Outflowsecurity.xml and Inflowsecurity.xml they should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="action">
<xs:annotation>
<xs:documentation>Outflow security 'action' configuration</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="items" type="xs:string"/>
<xs:element name="user" type="xs:string"/>
<xs:element name="passwordCallbackClass" type="xs:string" minOccurs="0"/>
<xs:element name="signaturePropFile" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionPropFile" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionPropFile" type="xs:string" minOccurs="0"/>
<xs:element name="signatureKeyIdentifier" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionKeyIdentifier" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionUser" type="xs:string" minOccurs="0"/>
<xs:element name="signatureParts" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionParts" type="xs:string" minOccurs="0"/>
<xs:element name="optimizeParts" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionSymAlgorithm" type="xs:string" minOccurs="0"/>
<xs:element name="EmbeddedKeyCallbackClass" type="xs:string" minOccurs="0"/>
<xs:element name="encryptionKeyTransportAlgorithm" type="xs:string" minOccurs="0"/>
<xs:element name="EmbeddedKeyName" type="xs:string" minOccurs="0"/>
<xs:element name="timeToLive" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
for more details go to the Apache help Page
To use the authentification in the Request you need to add a Tag to the soap:Header
<soapenv:Header>
<wsse:Security
soapenv:mustUnderstand="1">
<wsu:Timestamp
wsu:Id="Timestamp-31497899">
<wsu:Created>2008-02-06T13:39:50.943Z</wsu:Created>
<wsu:Expires>2008-02-06T13:44:50.943Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken
wsu:Id="UsernameToken-10697954">
<wsse:Username>apache</wsse:Username>
<wsse:Password
Type="http://...#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
the namespaces are:
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"