I'm writing a SOAP client. I'm using gSOAP version 2.7.17 and I have to stick to that version as the server is using this one and I cannot modify it as it is already running in the field.
When I do my SOAP call, I always receive empty answer! However, when I sniff the network, the XML answer seems correct:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:Supervisor="urn:Supervisor"
xmlns:ActiveLogin="urn:ActiveLogin" xmlns:TechLogin="urn:TechLogin"
xmlns:UMSLogin="urn:UMSLogin">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<unitCallResponse>
<szServerName>UMS_DEV_LANCC2 (2)</szServerName>
<dResponse>cUNITRETURNCODE_RESTARTIMMEDIATE</dResponse>
<dDetail>cBla</dDetail>
</unitCallResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here is a simplified code snippet about how I perform the SOAP call with the proxy generated with soapcpp2:
UMSLogin::unitCallResponse response; // Response from SOAP
UMSLogin::UMSLoginProxy* m_soapProxy = // The SOAP proxy
new UMSLogin::UMSLoginProxy(SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
callRes = m_soapProxy->unitCall(m_eUnitType, serial, m_dInterfaceVersion,
xl2CallTypeToUmsLoginCallType(m_pSoapEndPoint->getCallType()),
xl2CommTypeToUmsLoginCommType(m_pSoapEndPoint->getComType()),
response);
logDebug(LOG_COM_DEVICE, "SOAP call done to %s, SOAP code %i, central code %i",
response.szServerName.c_str(), callRes, response.dResponse);
m_soapProxy->soap_close_socket();
m_soapProxy->destroy();
delete m_soapProxy;
The actual output:
SOAP call done to , SOAP code 0, central code 0
When I expect
SOAP call done to UMS_DEV_LANCC2 (2), SOAP code 0, central code 5
/* 5 -> cUNITRETURNCODE_RESTARTIMMEDIATE */
There was an old implementation that was working previously, this must be working! Where am I wrong? Did anyone has already had this kind of problem? Any pointer is strongly appreciated!
EDIT:
Problem was "solved" by using an earlier version of SOAP (2.7.14) without changing a single line of code from the original version of my program. However, I have the feeling I miss something important again! I should probably tweak a little my header file giving the SOAP "definitions" to make things working ...
Looking at your code you declare response and then reference the elements of it as response.dResponse. This seems to imply that response is a struct rather than a pointer to a struct so after you call m_soapProxy->unitCall the version of response that you then report on hasn't changed, only the copy in m_soapProxy->unitCall will have changed.
I'd try tracing this call through in the debugger and see what is actually happening in m_soapProxy->unitCall. BTW is it you code or generated by GSOAP?
Related
I've got a .NET web service that has a method that accepts a string. In Mulesoft's Anypoint studio, I've successfully built a flow that accepts a POST, passes the POSTed string into the service, and returns a manipulated result.
I'm now trying to create a flow for a similar service, except that this service accepts a custom object, not a string. When I use SOAP UI to test my service directly, I pass in the following XML and it successfully builds the object in my service and the MyFirstString and MySecondString values are available to the service.
SOAP UI XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pra="http://schemas.datacontract.org/2004/07/Pra.Lib.Transformation">
<soapenv:Header/>
<soapenv:Body>
<tem:Transform>
<tem:transformationData>
<pra:MyFirstString>test1</pra:MyFirstString>
<pra:MySecondString>test2</pra:MySecondString>
</tem:transformationData>
</tem:Transform>
</soapenv:Body>
</soapenv:Envelope>
However, when I use my Mule flow and drop my DataWeave in front of my Web Service Consumer, it auto-builds an XML string that doesn't work with the service. When I attach a debugger to the service, it shows that the object is not built/mapped successfully...MyFirstString and MySecondString are null after the Web Service Consumer call is made.
DataWeave code:
%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
---
//Some output fields where skipped as the structure is too deep (more than 2 levels).
//To add missing fields click on the scaffold icon (second on the toolbar).
{
ns0#Transform: {
ns0#transformationData: {
Xml: "test1",
Xslt: "test2"
}
}
}
DataWeave output:
<?xml version='1.0' encoding='windows-1252'?>
<ns0:Transform xmlns:ns0="http://tempuri.org/">
<ns0:transformationData>
<Xml>test1</Xml>
<Xslt>test2</Xslt>
</ns0:transformationData>
</ns0:Transform>
The error message returned is "Error in deserializing body of request message for operation 'Transform'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'Transform' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'EXTRACT_DETAIL' and namespace ''. Message payload is of type: ElementNSImpl"
So if I understand this error...my question is how do I code the DataWeave to output in the soap envelope format that SOAP UI uses...because it seems that the element structure DataWeave generates is what's giving me problems? Thanks much.
A fellow developer was able to point me in the right direction. In AnyPoint Studio, on the properties tab for the DataWeave/TransformMessage component, I had to click the button to Scaffold Output Structure. That generated the following output (syntax changes bolded below). I had originally been under the impression that all scaffolding was automatic when first dropping the component into a flow.
Syntax that changed:
ns1#Xml: "test1",
ns1#Xslt: "test2"
Entire scaffolding:
%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
---
//Some output fields where skipped as the structure is too deep (more than 2 levels).
//To add missing fields click on the scaffold icon (second on the toolbar).
{
ns0#Transform: {
ns0#transformationData: {
ns1#Xml: "test1",
ns1#Xslt: "test2"
}
}
}
Click here for Scaffold button
screen capture
Yes after configuring your WSDL you can drag and drop Data Weave and then click on scaffold , it will generate appropriate structure for you.
I am using CXF JAXWS Client for retrieving some information from an external web services. So, basically, we have .xsd and .wsdl files from the external and try to implement our ws consumer by generating the client stubs using cxf-codegen-plugin. We cannot change the .xsd and .wsdl files. Everything works fine, we are able to send and retrieve soap messges from the external services.
However, when I look into the soap request message from the log, I find a lot of unused namespaces in the soap (body) message sent from our ws client.
Below is an example
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:aheaderns="http://xxx.xxx.xxx.xxx/header.xsd">
<soap:Header>
...
</soap:Header>
<soap:Body>
<ns7:requestQuery xmlns:ns15="http://xxx.xxx.xxx.xxx/AAA" xmlns:ns14="http://xxx.xxx.xxx.xxx/BBB" xmlns:ns13="http://xxx.xxx.xxx.xxx/DDD" xmlns:ns12="http://xxx.xxx.xxx.xxx/CCC" xmlns:ns11="http://xxx.xxx.xxx.xxx/EEE" xmlns:ns10="http://xxx.xxx.xxx.xxx/FFF" xmlns:ns9="http://xxx.xxx.xxx.xxx/GGG" xmlns:ns8="http://xxx.xxx.xxx.xxx/HHH" xmlns:ns7="http://xxx.xxx.xxx.xxx/III" xmlns:ns6="http://xxx.xxx.xxx.xxx/JJJ" xmlns:ns5="http://xxx.xxx.xxx.xxx/KKK">
<ns7:sample>
<ns7:type>A</ns7:type>
<ns7:ref>1</ns7:ref>
</ns7:sample>
</ns7:requestQuery>
</soap:Body>
Is there any way to remove the unused namespaces from the outbound soap message sending from the client?
You could move your client proxy classes to the same package and map it to the proposed namespace specified in the wsdl.
Put this code into the package-info.java class:
#XmlSchema(xmlns = { #XmlNs(prefix = "ns1", namespaceURI = "http://xxx.xxx.xxx") },
namespace = "http://xxx.xxx.xxx")
package clinet.sample.proxy;
import javax.xml.bind.annotation.XmlNs;
Hope this helps.
After digging into this problem for quite sometime, I found the solution. However, I think my solution is not to solve the problem at the root cause but it works for now.
Basically, I use XSLTOutInterceptor from CXF to apply the XSL to the out message. However, the default PRE_STEAM phase is not working for me. Then, I decide to extend the XSLTOutInterceptor so as to change its PHASE to WRITE. So that, the unused namespaces will be removed during the writing of the protocol message before sending it out.
The XSL I use is from how to remove unused namespaces from source xml
By the way, I still have no idea why those unused namespaces have been generated. If anyone could give me a suggestion, I would appreciate it.
Thanks :)
I'm calling a .Net Web Service which takes a complex type as a parameter (using KSoap2). I've done this before successfully so I decided to just copy my old code and paste it into a new method, replacing some code with code relevant to the current web service of course.
The only real difference I can see is that the URL to the new web service's .asmx is different.
The thing is I keep getting the following error:
(I get the following when SoapEnvelope.VER11)
org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}soap:Fault>#1:338 in java.io.InputStreamReader#199cb474)
(And the following when SoapEnvelope.VER12)
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/soap/envelope/}soap:Envelope>#1:207 in java.io.InputStreamReader#5b209e72
Why would the error message change like this depending on the version of SOAP I use?
I also tried printing out my envelope with HttpTransport.requestDump and I get the following:
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<postMessage xmlns="http://www.magnatech.com/" id="o0" c:root="1">
<myMessage i:type="n0:Message" xmlns:n0="http://www.magnatech.com/">
<messageContent i:type="d:string">HEY</messageContent>
<userName i:type="d:string">TEST USERNAME</userName>
<agentName i:type="d:string">TEST AGENT NAME</agentName>
<userID i:type="d:string">0</userID>
<agentID i:type="d:string">0</agentID>
<fromAgent i:type="d:string">false</fromAgent>
<messageID i:type="d:string"></messageID>
<accountNumber i:type="d:string">TEST ACCOUNT</accountNumber>
</myMessage>
</postMessage>
</v:Body>
Which looks fine, I actually did the same thing with the envelope from my other "WORKING" web service call and they are the same, except for the element names of course.
And finally, here is the output from HttpTransport.responseDump:
<?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><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Could not deserialize Soap message</faultstring></soap:Fault></soap:Body></soap:Envelope>
So obviously there is something wrong with the envelope as I'm sending it, yet I see nothing wrong with it.
What could be the problem? I've tried everything possible and am running out of ideas.
Any help at all will be greatly appreciated.
Thanks
I have a ASP.NET Webservice and am trying to call it from the BizTalk. Now I've managed for the webservice to actually be entered, but the object can't be mapped and always returns NULL. After trying and testing I finally found out that the one thing that makes it fail the mapping is the namespace on the root node. Now I have no clue how I can remove that namespace or would it be better to somehow try to adjust the webservice to use the namespace?
My Service Method:
public bool CreateBasket(Basket basket)
{
if(basket == null)
throw new Exception(string.Format("Basket could not be mapped on the service."));
_entities.AddToBaskets(basket);
foreach (var item in basket.Items)
{
_entities.AddToItems(item);
}
return _entities.SaveChanges() > 0;
}
The basket object is created by the Entity Model.
This call works:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CreateBasket xmlns="http://tempuri.org/">
<basket xmlns:ns0="http://schemas.datacontract.org/2004/07/OC.SampleCustomer.WCFService" xmlns:ns1="http://schemas.datacontract.org/2004/07/System.Data" xmlns:ns2="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/">
<ns0:BillingId>5</ns0:BillingId>
This call doesn't work:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CreateBasket xmlns="http://tempuri.org/">
<ns0:basket xmlns:ns0="http://schemas.datacontract.org/2004/07/OC.SampleCustomer.WCFService" xmlns:ns1="http://schemas.datacontract.org/2004/07/System.Data" xmlns:ns2="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/">
<ns0:BillingId>5</ns0:BillingId>
Edit
The BizTalk recieves the error I throw in my service method in the recieve body. So my error message on the biztalk server is "Basket could not be mapped on the service."
I gave up on the entity framework and created my own objects with defined namespaces for the WCF service and now it works. Thanks for the help, I'll keep playing around with it till I understand more =)
I'm deploying a StatelessSessionBean annotated with #WebService to JBoss. I'm taking the WSDL generated by JBoss to generate client stubs. My problem is in calling a method which returns a list of objects. If the list is empty the call succeeds however if the list is not empty then I get the following exception:
com.sun.xml.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.bind.UnmarshalException: Unable to create an instance of com.companyname.api.ws.DataItemType
- with linked exception:
[java.lang.InstantiationException]]
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:124)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
at $Proxy34.getWorkflows(Unknown Source)
at com.companyname.api.SimpleClient.go(SimpleClient.java:48)
Searching the web led me to this discussion here: http://forums.java.net/jive/message.jspa?messageID=281780
However I have set the #XmlSeeAlso stuff correctly and it is present on the generated stub classes. I can confirm that the DataItemType class is abstract so it is not surprising that an attempt to instantiate it causes a problem. I'm not at all clear on why the DataItemType class is being instantiated at all (as it is abstract). This is the XML that is returned from the server (it looks about right to me):
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header></env:Header>
<env:Body>
<ns2:getWorkflowsResponse xmlns:ns2="http://ws.api.companyname.com/">
<return>
<id>
<identifier>1</identifier>
<version>0</version>
</id>
<goal>ENROLL</goal>
<dataItemType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DataItemTypeText">
<attributeName>email</attributeName>
<displayName>Email Address</displayName>
</dataItemType>
...
</return>
</ns2:getWorkflowsResponse>
</env:Body>
</env:Envelope>
Does anyone know what I'm doing wrong?
There were a number of issues with the generated WSDL (note that it wasn't a handcrafted one). There was nothing specific that I changed which indicated why this particular exception was thrown (or why, for example, there wasn't a failure when generating the incorrect WSDL).
Once I adjusted the annotations so that a valid WSDL was created then I had further issues which the JAX-WS versions I was using. I ended up upgrading the version used by JBoss which, in turn, led to me needing put the newer JAX-WS jars in my JRE endorsed directory.
I'm not going to detail what I did in any more detail as there was no specific thing that I did that addressed this problem. If anyone else sees it I would suggest being very specific in the annotations you use to generate your WSDL and taking a careful look at your WSDL.