Configuring CXF web service client to read XML 1.1 responses - web-services

I'm using CXF to generate an interface to a .NET web service client. However, sometimes when I use the client, I get an error:
WARNING: Interceptor for {http://xxxxxx.com}ChangeRequestWebService#{http://xxxxxx.com/ChangeRequestWebService}GetChangeRequestById has thrown exception, unwinding now
[com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x1b
at [row,col {unknown-source}]: [76,44]
From many other sources online, it's obvious that this is because the webservice is encoding its response in XML 1.1, while my CXF client is reading that response expecting XML 1.0, and the special character 0x1b is illegal in XML 1.0. Now, I don't want to argue about whether the .NET service should be using XML 1.1 in its response, when the WSDL is obviously 1.0 (since that's the spec). I just want to be able to read what they send without errors.
Looking at the dependencies in the CXF client, they use WoodStox 4.1.1 which (from their site) clearly supports XML 1.1. What I want to know is, is there any way to configure my CXF client (via binding at wsdl2java time, or during run-time) to use an XML 1.1 parser when receiving responses? All I can find is people saying that they shouldn't be using 1.1, or having the server-side filter these characters. Note that I can't filter the characters client-side, as I have to send the data back to the server, and validation would fail.
As an alternative, I suppose the .NET service could in some fashion SPECIFY that they're using XML 1.1 in their response, but I don't control that service, so it would be more troublesome to figure out their problem for them and then suggest they fix it. Plus, the data they're sending is in a DB, so it's not the web service's fault that it has XML 1.1-only characters in it.

It looks like the answer is... there is no way to pre-configure CXF to expect XML 1.1 by default.
Essentially, if XML comes in without a version tag:
<?xml version="1.1">
Then it isn't XML 1.1. That's the problem here. If the xml header existed and specified XML 1.1, then the parser in CXF would parse it as XML 1.1. .NET web services don't (by default) send any XML header tag, so the parser in CXF parses it (correctly) as XML 1.0.
That said, there might be a way to catch the input stream before it gets parsed by CXF, and "insert" an XML version header that specifies 1.1, which would "fix" the problem for me. If I find a way to get it to work, I'll post it.

Related

How to return JSON response from soap based web service.

SOAP based web service is implemented in Apache CXF JAX WS and returns xml based response. I have one JavaScript client for which I want to return JSON from this service.
As CollinD commented, my answer to the (now deleted) question https://stackoverflow.com/a/9140399/155689 would work.
Just include the JSON inside the body of a Soap response by wrapping it with CDATA tags. Inside CXF you could stringify, even encode the json if you want to (in case, for some weird reason the JSON payload might include a CDATA tag or similar).
How the javascript client reads the SOAP response depends on the JS framework but if that is already taken care of then it just needs to (optionally) decode the body payload and load as JSON as normal.

How can I call a ASP.Net made web service without using MSXML?

I am using a very particular language named “Magik”, I used to use MSXML2 to run web services but in one of my projects I failed to use MSXML, I tried a lot of thing to make it work from changing MSXML.DLL and testing different version of MSXML, using MSXMLHttpServer and all the things you may think of, I somehow ate MSDN website but didn’t find anything helpfull.
Now I am looking for other ways of calling a SOAP webservice, someone said you may post your XML to web method address by parsing and using a query string, But I didn’t succeed to do so.
I can also negotiate via TCP/IP, Can I send my XML to a web service using a TCP/IP connection?
If there is any other way that do the job I really appreciate it.
Currently I am connecting Magik to a Java application and when I need to call a web service I send my request to that Java application (there is a Jar file which creates a data-bus between a Magik session and a Java Application) I have also wrote the Java part using Axis technology. But this is a very hard job and I should change a lot of things to only keep my project up and match with a small change in web service that I consume.
Using MSXML were so easy formerly, sadly it does not work now!
First note that you can not use GET to call SOAP web services only POST will work with SOAP, GET can be used for REST but you mentioned SOAP only.
I can introduce you two method that you may use to call a web service instead of your MSXML which does not work anymore.
Using Test Form (Web Service Test Page)
You may ask your .Net web services provider to create a test form for his own web service and you create a query string which suppose to emulate the data on the form, actually you are using the web services tester page to send your data via query string to it and it will complete the rest for you.
Using TCPIP
use a TCP/IP Connection, in this method you need to create a header above your xml to set the parameters that a web service consumer should fill (remember MSXML and Content-Type, Content-Length, SOAPAction, Host, …….)
then translate your string to a byte vector since all programming language which can create a TCPIP Socket just accept a byte vector while inputing or outputing data to that connection. after translating the string you are ready to send the data to your web services address.
take a look at the following example of how you may create a string to send to a TCPIP socket.
POST /globalweather.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.webserviceX.NET/GetCitiesByCountry"
<?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>
<GetCitiesByCountry xmlns="http://www.webserviceX.NET">
<CountryName>Egypt</CountryName>
</GetCitiesByCountry>
</soap:Body>
</soap:Envelope>
You may send above string to http://www.webservicex.net/globalweather.asmx
You may check to following link if you need detailed information about how to consume a web service using TCPIP
http://www.codeproject.com/Articles/312530/Calling-Webservice-Using-TCP-IP-from-any-Programmi

Technically,to create soap message, WSDL file is a must?

I'm using the SoapUI to generate the soap request. It hints me to input the wsdl file. I do it, and it create the soap-style message. Everything is OK.
But I have a doubt. If I have webservice without any WSDL file, can I still generate the soap-style message by hand? If it can, how to?
Or if I know the webservice need to input two int paramaters and return one string value, can I speculate the soap message only by these limited information?
If you are just doing -requests- then you don't need to have the WSDL file if you know the specific service you're asking and the parameters as you say. You can even do it by hand by creating the request and then sending it over HTTP (for example you could create it with your editor in a file and then send it via wget or curl).
As for an example I'll cite wikipedia:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
</soap:Header>
<soap:Body>
<m:GetStockPrice xmlns:m="http://www.example.org/stock">
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
What you need to change is the parts in the soap:Body: of course the GetStockPrice (which is the service you're accessing) and StockName which is the parameter (in your case you may have more than one).
If in doubt you can put something to listen on a socket (for example netcat) and make your application with WSDL do a query to it and see the exact informations, then remove WSDL and work "by hand".
In Java: If you have webservice (annotated class etc.), the your server create one WSDL file when you deployed it. This WSDL you can use for soapUi.
If you have any structure (endpoint, class, XSD etc.), you can create soap message by hand.
If you weren't use WSDL for soap message, it wouldn't call/send this message. So the wsdl document is a required element according to the protocol. WSDL describes of how the service can be called, what parameters it expects, and what data structures it returns.
From Wikipedia:
WSDL is often used in combination with SOAP and an XML Schema to
provide Web services over the Internet. A client program connecting to
a Web service can read the WSDL file to determine what operations are
available on the server. Any special datatypes used are embedded in
the WSDL file in the form of XML Schema. The client can then use SOAP
to actually call one of the operations listed in the WSDL file using
for example XML over HTTP.
Here is in example for invoking web service dynamically. In this case the author doesn't know the description of the WSDL.
The purpose of the WSDL is to describe the service.
This machine-readable description allows computer programs to create clients that know how to call the service and process the responses.

Send/Receive a SOAP request using SPRING JAVA

I am new to Spring web services. I am going to create an xml request, and send it as a SOAP request to a web service and receive the response.I read different documents but still confused as I could not find a working sample yet.
I know that I should use WebServiceTemplate and WebServiceMessageSender, SaajSoapmessageFactory (please let me know if I am wrong) but not sure how to use them.
Do I need WSDL? if yes why?
If you have any sample code please send me to get clear on it.
Thanks
If you want to send SOAP requests, you would like to be a SOAP client. Seems like you want to use spring-ws project. Check out their great documentation on the client side. The same documentation will guide you through the process of creating a server. There are plenty of examples and ready-made configuration snippets waiting for you.
Spring-WS is built on top of XML Schema description of your message, so you will need WSDL to generate e.g. JAXB models of your requests and responses.
AFAIK, for "web services" , the WSDL file is the machine blueprint of the "ports" as they are called However! ports in WSDL "means" java language(or any other programming language used with a routine or sub or procedure or function) method and has a specific naming scheme associate the .wsdl xml file(template of the service). Each WSDL port(language method) has specifications of return value and data specifications for how to feed it arguments and their type values.

Webservice Response Ends with --UUID

I am using cxf framework in order to expose some web services.
When i tested it using soap-ui, it works great. But one of our customers that uses different soap client complains that the message ends with:
/soap:Envelope>
--uuid:91c5694a-93f5-404c-ab2b-8c220b7f289f--
I searched the web, and i found that this line apears not only in our system. But I couldn't figure out whether this suffix is valid and well-formed, or not.
Is there any reference that document this issue?
Is it really valid?
How can I remove it?
Thanks!
It sounds like you have MTOM enabled on the server side. In that case, the SOAP message is wrapped in mime wrappers (which is per spec). The --uuid thing is a marker of a mime part. If the client is having issues with those, then it sounds like that client cannot handle MTOM. You COULD turn MTOM off for those clients.