Re: Perl web service consumed by c# client returns null.
by haj (Vicar) on Dec 12, 2019 at 16:38 UTC
|
Isn't the error message quite clear? It looks as if the web service fails to provide a Content-Type header, but the client expects one. According to RFC7231, the web service SHOULD provide that header, and apparently the C# client doesn't want to guess. The message tells you that the client expects a content type of text/xml, which is fair enough. | [reply] |
|
|
It looks as if the web service fails to provide a Content-Type header, but the client expects one.
I'm not the original Anonymous Monk, but will respond: I would have thought the same thing, except that the error message is included in the message, and appears to be showing the content that the client received. That message shows not one but two Content-Type headers. If the error message isn't showing what was received from the service, but some other content, I would be confused as a user of that client.
I'm wondering if seeing two Content-Type headers instead of one-and-only-one is confusing the client. Or maybe the headers don't have the expected newline sequence, so it shows up when printed as being on multiple lines, but the client either sees it as one line or sees extra characters at the start or end of each of the header lines.
(edit first paragraph for clarity)
| [reply] |
|
|
Ah, indeed. Thanks for pointing that out!
So the first header is Content-type (with a lowercase "t" in type), and it seems to come before the HTTP 1.1 line. This is an invalid HTTP response and might cause the client to abort parsing. If that's the case, then the error message isn't as good as it could be...
| [reply] |
|
|
| [reply] [d/l] [select] |
Re: Perl web service consumed by c# client returns null.
by Anonymous Monk on Dec 13, 2019 at 08:09 UTC
|
Hi, Monks,
Please don't get confused with two headers. first header you see is typed by me in the perl webservice to see what web service is returning.
Line from Http is what web service seems returning, but c# client getting null value.
Exception: System.InvalidOperationException: Client found response con
+tent type of '', but expected 'text/xml'.
The request failed with the error message:
--
Content-Type : text/xml #I have added this line in the perl web servic
+e like print "\nContent-type : text/xml\n\n" to check what exactly it
+ returns.
####################################################################
HTTP/1.1 200 OK
Content-Length: 1468
Content-Type: text/xml; charset=utf-8
SOAPServer: SOAP::Lite/Perl/1.17
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyl
+e="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://sche
+mas.xmlsoap
.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/en
+coding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http
+://www.w3.o
rg/2001/XMLSchema-instance"><soap:Body><MRWebServices__searchResponse
+xmlns="MRWebServices"><return xsi:type="xsd:string"><data>
<array>
<item key="0">
<map>
<item key="mrid">1</item>
<item key="mrtitle">Test ticket for edit issue.</item>
</map>
</item>
<item key="1">
<map>
<item key="mrid">2</item>
<item key="mrtitle">Test ticket for edit issue2.</item>
</map>
</item>
<item key="2">
<map>
<item key="mrid">3</item>
<item key="mrtitle">Test ticket for edit issue3.</item>
</map>
</item>
<item key="3">
<map>
<item key="mrid">4</item>
<item key="mrtitle">Test ticket for edit issue4.</item>
</map>
</item>
<item key="4">
<map>
<item key="mrid">5</item>
<item key="mrtitle">Test ticket for edit issue5.</item>
</map>
</item>
</array>
</data>
</return></MRWebServices__searchResponse></soap:Body></soap:Envelope>
--.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadRespons
+e(SoapClientMessage message, WebResponse response, Stream responseStr
+eam, Boolea
n asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(Stri
+ng methodName, Object[] parameters)
at Search.MRWebServices__search(String usr, String pw, String extra
+Info, String query)
at main.Main()
Thank you.
| [reply] [d/l] |
|
|
So now you got me really confused.
The text beginning with Exception: System.InvalidOperationException: looks as if it is printed by the C# client, as Perl doesn't throw such an exception. The stack trace at the end also looks rather C#-ish to me. So who is composing the "error message" enclosed by the two -- strings, and from what input? You write I have added this line in the perl web service - but apparently the client embedded it into its "error message."
The string printed by print "\nContent-type : text/xml\n\n" useless for debugging, it is just a constant. If you send it to the client, then it breaks the HTTP response. You should at least do something like that:
print "HTTP/1.1 200 OK\n;
print "Content-type : text/plain\n\n";
...because after inserting these lines, the content type of the response is no longer valid XML, but can still be read as text.
You could, of course, also point a simple client like LWP's HEAD program to the service to check whether the response is well-formed. | [reply] [d/l] |
|
|
Exception: System.InvalidOperationException: Response is not well-form
+ed XML. ---> System.Xml.XmlException: Data at the root level is inval
+id. Line 1,
position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadRespons
+e(SoapClientMessage message, WebResponse response, Stream responseStr
+eam, Boolea
n asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(Stri
+ng methodName, Object[] parameters)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(Stri
+ng methodName, Object[] parameters)
at Search.MRWebServices__search(String usr, String pw, String extra
+Info, String query)
at main.Main()
Thank you
| [reply] [d/l] |
|
|
|
|
|
|
|
|
|
Content-Type : text/xml #I have added this line in the perl web service like print "\nContent-type : text/xml\n\n" to check what exactly it returns.
if you have access to the service code, it would be trivial to crack. For example, start by finding out why the error message complains that it found an empty Content-Type but you print text/xml and your client sends text/xml; charset=utf-8 | [reply] [d/l] [select] |