1) Is it important to set the correct mime type for a web service response?
Yes. However, this is really dependent on how the recipient is expected or configured to process the content. A client which is built using out-of-band information about the content may choose to ignore the content type or a client can use the content-type metadata to route the representationt to an appropriate processing module based on the content type. Content-Type enables a client make sense of the content without having to peek into the actual content. Also, since you have marked your question as related to REST, it is important to understand the self-descriptive constraint of REST and what role the media types plays to acheive this constraint. If you are interested to learn more about self-descriptiveness, read section 5.2.1 of Roy's dissertation.
2) what is the correct mime type for
a, a) XML response?
b) JSON response?
application/xml
text/xml
application/json
application/x-javascript
text/javascript text/x-javascript
text/x-jsontext/x-json
All the above content types are generic and gives no more information to the client apart from saying if the content is JSON or XML. What you need is specific content-type for your application which not only tells your client about the format but also describes the semantics and how to process the content. As for the difference between application/xxx and text/xxx, RFC 3023 states the following:
If an XML document that is, the
unprocessed, source XML document is
readable by casual users, text/xml is
preferable to application/xml. MIME
user agents (and web user agents) that
do not have explicit support for
text/xml will treat it as text/plain,
for example, by displaying the XML
MIME entity as plain text.
Application/xml is preferable when the
XML MIME entity is unreadable by
casual users. I have read in some
discussions that text/xml may be
deprecated in future but I am not sure
of that.of that.
For JSON, the correct MIME type is application/json. See SO question.