how to prevent parsing webservice response string - web-services

how can I prevent string argument from beeing parsed as xml ?
<s:element name="MyResponse">
<s:complexType>
<s:sequence>
<s:element type="s:string" name="xmlResultWithStringType" minOccurs="0" maxOccurs="1" />
</s:sequence>
</s:complexType>
</s:element>
in log I have a correct answer -
Hello xmlStart <foo>in foo<bar>in bar</bar> end foo</foo> xmlEnd
full log :
---[HTTP request - http://localhost:8080/mockXXX]---
Accept: application/soap+xml, multipart/related
Content-Type: application/soap+xml; charset=utf-8;action="http://xxx"
User-Agent: JAX-WS RI 2.2.7-b01 svn-revision#13316
<?xml version="1.0" ?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Body><MyRequest xmlns="http://fff"><xmlRequest>req do webserwisu</xmlRequest></MyRequest></S:Body></S:Envelope>--------------------
---[HTTP response - http://localhost:8080/mockXXX - 200]---
null: HTTP/1.1 200 OK
Content-Type: application/soap+xml;charset=UTF-8
Server: Jetty(6.1.x)
Transfer-Encoding: chunked
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:fff="http://fff">
<soap:Header/>
<soap:Body>
<fff:MyResponse>
<!--Optional:-->
<fff:XmlResultWithStringType>Hello xmlStart <foo>in foo<bar>in bar</bar> end foo</foo> xmlEnd</fff:XmlResultWithStringType>
</fff:MyResponse>
</soap:Body>
</soap:Envelope>--------------------
but webservice call returns only
xmlEnd2
whole beginning is lost, the content of XmlResultWithStringType is parsed by xml parser,
but it should not,
how can I prevent it from beeing parsed ?
I use jax-ws-RI implementation,

it should be but into CDATA section
<![CDATA[ any xml possible here, it won't be treated as xml but as string ]]>
otherwise, without CDATA, it is treated as xml not as string.

Related

MTOM attachment encoded twice in SOAP payload

I am sure this is just pilot error, but cannot find a solution. Have a jax-ws web service with a soap payload operation that includes an attachment. Here is a snippet of the schema doc. This is the type defined:
<xs:complexType name="BinaryAttachmentType">
<xs:simpleContent>
<xs:restriction base="xmime:base64Binary">
<xs:attribute ref="xmime:contentType" use="required" />
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
Embedded in this element definition:
<xs:element name="Contact">
<xs:complexType>
<xs:sequence>
<!-- removed other elements -->
<xs:element name="Attachment" type="BinaryAttachmentType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element
Using soapUI, SOAP looks like:
<hsn:Contact>
<!-- other elements -->
<hsn:Attachment xm:contentType="image/jpeg">cid:323665198529</hsn:Attachment>
</hsn:Contact>
Attached file in soapUI:
When I look at http from log:
http Header:
"Content-Type: multipart/related; type="text/xml"; start="<rootpart#soapui.org>"; boundary="----=_Part_15_23791896.1485382707426""
"SOAPAction: "http://hsn.us.banner.hsntech.com/Level1Request""
"MIME-Version: 1.0"
"Content-Length: 104164"
"Host: localhost:7001"
"User-Agent: Apache-HttpClient/4.1.1 (java 1.5)"
"------=_Part_15_23791896.1485382707426"
"Content-Type: text/xml; charset=UTF-8"
"Content-Transfer-Encoding: 8bit"
"Content-ID: <rootpart#soapui.org>"
in SOAP body, see attachment element with base64-encoded file:
<hsn:AttachmentFileName>test1.jpg</hsn:AttachmentFileName>
<hsn:Attachment xm:contentType="image/jpeg">/9j/4AAQSkZJRgABAQEAYABgAAD .. rest of base64 encoding
then after SOAP message, encoded attachment again:
------=_Part_15_23791896.1485382707426
Content-Type: image/jpeg;
name=Foo.jpg
Content-Transfer-Encoding: binary
Content-ID: <Foo.jpg>
Content-Disposition: attachment; name=Foo.jpg; filename=Foo.jpg
(... encoded attachment again )
[0xff][0xd8][0xff][0xe0][0x0][0x10]JFIF[0x0][0x1][0x1][0x1][0x0]`[0x0]`[0x0][0x0][0xff][0xdb][0x0]C[0x0][\n]
So, why the file encoded twice in the request? Thanks.
Check that Enable MTOM is set to True in the Request Properties:

How can I resolve "unexpected encoding style" using Savon Gem with Ruby on Rails

I am getting the following error when accessing a WSDL SOAP server:
{:error=>true, :message=>"Savon::SOAPFault: (env:Client) JAXRPCTIE01: caught exception while handling request: unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual="}
I went to soapclient.com to figure out what it's looking for.
Here is the error message I'm receiving.
Here is the code I'm using to connect to the SOAP client:
my_hash_of_stuff = {
zipcode: d_zip,
country: country
}
wsdl = 'http://my.yrc.com/dynamic/national/WebServices/YRCZipFinder_V1.wsdl'
client = Savon.client(wsdl: wsdl,
logger: Rails.logger,
log_level: :debug,
log: true,
pretty_print_xml: true,
env_namespace: :'soap-env',
strip_namespaces: true
)
response = client.call(:lookup_zip, message: my_hash_of_stuff)
print response.to_hash
Here's a copy of my log output so you can see what's happening.
This appears to be what the SOAP request should look like according to soapclient.com (if i'm understanding it correctly).
This is what I am sending.
I've been fighting with it all day and I'm sure it's probably a combination of my ignorance and something simple that i'm missing. Hopefully you guys might be able to help?
EDIT 05/25/2016:
So, looking at this again today, here's the log showing the request that savon is making:
HTTPI GET request to my.yrc.com (net_http)
SOAP request: http://my.yrc.com/dynamic/national/webservice/YRCZipFinder_V1
SOAPAction: "http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl/lookupCity", Content-Type: text/xml;charset=UTF-8, Content-Length: 417
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<tns:lookupCity>
<zipCode>84101</zipCode>
<country>USA</country>
</tns:lookupCity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here's what a correct one looks like. I got this from the existing php app and tested it in Postman to verify that it works:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://my.yrc.com/national/WebServices/YRCZipFinderMessages_V1.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:lookupCity>
<lookupCityRequest xsi:type="ns2:YRCLookupCityRequest">
<zipCode xsi:type="xsd:string">84101</zipCode>
<country xsi:type="ns2:CountryCode">USA</country>
</lookupCityRequest>
</ns1:lookupCity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
UPDATE:
After some more hacking, I have my request looking like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://my.yrc.com/national/WebServices/YRCZipFinderMessages_V1.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<tns:lookupCity lookupCityRequest="ns2:YRCLookupCityRequest">
<zipCode>84101</zipCode>
<country>USA</country>
</tns:lookupCity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I need to get lookupCityRequest to move inside lookupCity instead of being an attribute of lookupCity, however. Testing it in Postman, that appears to be the only stumbling block left to hurdle.
You can use the special :attribute!symbol to assign additional attributes. That's a functionality from Nokogiri which Savon uses to build XML.
require 'savon'
my_hash_of_stuff =
{ zipcode: "99103",
country: 'US',
attributes!: { :country => { 'xsi:type' => 'ns2:YRCLookupCityRequest'},
:zipcode => { 'xsi:type' => 'ns2:YRCLookupCityRequest' }}
}
wsdl = 'http://my.yrc.com/dynamic/national/WebServices/YRCZipFinder_V1.wsdl'
client = Savon.client(wsdl: wsdl,
# logger: Rails.logger,
log_level: :debug,
log: true,
pretty_print_xml: true,
env_namespace: :'soap-env',
strip_namespaces: true
)
response = client.call(:lookup_zip,
message: my_hash_of_stuff)
print response.to_hash
If nothing works and you're desperate enough then you can still create your very own XML and use xml: instead of message:.

EWS: unexpected SOAP validation error from Exchange 2013

I make a request with JAX-WS:
GetItemType itemRequest = new GetItemType()
.withItemShape(new ItemResponseShapeType()
.withBaseShape(DefaultShapeNamesType.ID_ONLY)
.withAdditionalProperties(new NonEmptyArrayOfPathsToElementType()
.withPath(objectFactory.createFieldURI(new PathToUnindexedFieldType()
.withFieldURI(UnindexedFieldURIType.ITEM_WEB_CLIENT_EDIT_FORM_QUERY_STRING)
)
)
)
)
.withItemIds(new NonEmptyArrayOfBaseItemIdsType()
.withItemIdOrOccurrenceItemIdOrRecurringMasterItemId(new ItemIdType()
.withId(id)
)
);
Which yields a soap message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns3:MailboxCulture xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages">nb-NO</ns3:MailboxCulture>
</soap:Header>
<soap:Body>
<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemShape>
<ns2:BaseShape>IdOnly</ns2:BaseShape>
<ns2:AdditionalProperties>
<ns2:FieldURI FieldURI="item:WebClientEditFormQueryString"/>
</ns2:AdditionalProperties>
</ItemShape>
<ItemIds>
<ns2:ItemId Id="AQAZAEF4ZWwuV2F0aG5lQHNwYXJlYmFuazEubm8ARgAAA7k+kh3x38JJgjb3IcQO3bAHAP4YJIRG6m5GkZN2+/hve1MAAAIBEAAAAP4YJIRG6m5GkZN2+/hve1MAAAIbBgAAAA=="/>
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>
And get this response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorSchemaValidation</faultcode>
<faultstring xml:lang="nb-NO">The request failed schema validation: The 'FieldURI' attribute is invalid - The value 'item:WebClientEditFormQueryString' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:UnindexedFieldURIType' - The Enumeration constraint failed.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorSchemaValidation</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The request failed schema validation.</e:Message>
<t:MessageXml xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:LineNumber>1</t:LineNumber>
<t:LinePosition>534</t:LinePosition>
<t:Violation>The 'FieldURI' attribute is invalid - The value 'item:WebClientEditFormQueryString' is invalid according to its datatype 'http://schemas.microsoft.com/exchange/services/2006/types:UnindexedFieldURIType' - The Enumeration constraint failed.</t:Violation>
</t:MessageXml>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
So it seems to not like the value item:WebClientReadFormQueryString, but this seems correct to me, according to the enumeration in types.xsd from EWS:
<xs:simpleType name="UnindexedFieldURIType">
<xs:restriction base="xs:string">
...
<xs:enumeration value="item:WebClientReadFormQueryString"/>
Does anyone understand this validation error, or is it a bug?
Exchange version is 15.0.913.19
Try adding a RequestServerVersion element in your SOAP header and setting it to at least Exchange2010.

mule simple web client soap request with wsdl

I would like to make request to web service from mule flow. So far I got WSDL generate classes (wsdl2java), prepared flow (below), and "successfully" send request. Now, problem is, that even thou I have taken base class from generated class and put it in payload it does not generate required soap.
My flow:
<flow name="flow1" doc:name="flow1">
<quartz:inbound-endpoint jobName="testingJob" repeatInterval="10810000" repeatCount="0" startDelay="5000" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job groupName="g1job" jobGroupName="g1job">
<quartz:payload>a</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<logger message="Starting quartz for testing purpouses" level="INFO" doc:name="Logger"/>
<custom-transformer class="com.example.GenerateSimpleRoutePublish" doc:name="Java"/>
<cxf:simple-client doc:name="SOAP" serviceClass="com.example.ws.MyWebService" operation="send">
</cxf:simple-client>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="9094" path="sync-server-web/services/myws" method="POST" connector-ref="http_internal" doc:name="HTTP"/>
</flow>
GenerateSimpleRoutePublish just put base object into payload and move on.
Result that is sent as soap request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:send xmlns:ns1="http://somenamespace.si/">
<ns1:arg0>
<ns1:MyRequest>
...
But it should look like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:send xmlns:ns1="http://somenamespace.si/">
<ns1:MyRequest>
...
Notice that is not there anymore in desired xml.
Anyone knows how to achieve that? I did googled a lot but just don't find right solution. If more is required then I can provide info.
Thanks!
EDIT
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="MyWebService" targetNamespace="http://ws.example.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://ws.example.com/"
version="1.0" xmlns:tns="http://ws.example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyRequest" type="tns:MyRequest" />
<xs:element name="send" type="tns:send" />
<xs:element name="sendResponse" type="tns:sendResponse" />
<xs:complexType name="send">
<xs:sequence>
<xs:element minOccurs="0" ref="tns:MyRequest" />
</xs:sequence>
</xs:complexType>
<xs:complexType final="extension restriction" name="MyRequest">
<xs:complexContent>
...
Transformer class GenerateSimpleRoutePublish.java:
#Override
public MuleEvent process(MuleEvent event) throws MuleException {
event.setMessage(transformMessage(event.getMessage(), event.getEncoding()));
// TODO Auto-generated method stub
return event;
}
public MuleMessage transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
MyRequest myRequest = new MyRequest();
/**
* some filling of testing data that is formatted correctly when soap is sent.
*/
Send send = new Send();
send.setMSyequest(myRequest);//the only setter method available for Send
message.setPayload(send);
return message;
}
Send.java methods and xml definition:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "send", propOrder = {"myRequest"})
public MyRequest getMyRequest()
public void setMyRequest(MyRequest value)
Instead of using a custom-transformer you could use Groovy script to send SOAP request to webservice client just as Java pojo class... Please check the reference :- https://m-square.com.au/consuming-net-wcf-soap-web-services-from-mule/

Access to Navision codeunit via web service (xml)

I try to access the Navision 2009 R2 web service by generating a SOAP message from C#. I get the response only if the codeunit's function I call has no parameters.
Example for codeunit RunJob function Test (no parameters, returns a hardcoded string):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
</Test>
</soap:Body>
</soap:Envelope>
As result I get that string...
Example for same codeunit RunJob function RunJob (takes 1 string parameter named parameter, returns an internal server error):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
<parameter>aaaa</parameter>
</RunJob>
</soap:Body>
</soap:Envelope>
As result I get the error (WebResponse wr = request.GetResponse();) instead of the needed info.
The most interesting thing is that it worked before. The only changes (as for me) - NAV 2013 was installed.
Has anyone experienced the same issue or knows the solution?
P.S.
Here is a part of the web service definition for the RunJob function:
<element name="Runjob">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="parameter" type="string"/>
</sequence>
</complexType>
</element>
<element name="Runjob_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
</sequence>
</complexType>
</element>
It was all about the function/variables naming.
The first letter of the each parameter of the function should be small one.
The SOAP body should be like this ("codeunit" is in lowercase, but it's name is as exposed in NAV)
<RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/RunJob">
...params...
</RunJob>
the Request header (codeunit name in lower case, function name as it is)
"urn:microsoft-dynamics-schemas/codeunit/runjob:RunJob"
It sound awkward but try to put
<soap:Body><RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
in single line, i.e. no carriage return between Body and RunJob.