Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Perl web service consumed by c# client returns null.

by haj (Vicar)
on Dec 13, 2019 at 09:52 UTC ( [id://11110058]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^3: Perl web service consumed by c# client returns null.
by Anonymous Monk on Dec 13, 2019 at 09:58 UTC

    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?

        If I don't print my own Content-type, I get below client side exception

        Exception: System.ArgumentNullException: Array cannot be null. Parameter name: bytes at System.Text.Encoding.GetString(Byte[] bytes) at main.Main()

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11110058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found