in reply to Perl web service consumed by c# client returns null.

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.

Replies are listed 'Best First'.
Re^2: Perl web service consumed by c# client returns null.
by haj (Vicar) on Dec 13, 2019 at 09:52 UTC

    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.

      Hi Haj,
      when I added print "Content-type : text/xml\n\n" in perl webservice, after this there is no content-type error but I am getting below error

      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

        Exception: System.InvalidOperationException: Response is not well-formed XML. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1

        So whatever you send to C# is not valid ("well-formed") XML. The problem is found at the first character in the first line, at the root element. See XML and Well-formed document.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Please read carefully what I wrote in my previous response.

        If you print an extra header, then the rest - which contains another HTTP header - is no longer valid XML.

        Now, what happens if you just don't print your own Content-Type header?

Re^2: Perl web service consumed by c# client returns null.
by bliako (Abbot) on Dec 13, 2019 at 09:16 UTC
    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