Link to home
Start Free TrialLog in
Avatar of bealem
bealem

asked on

Set MIME type on .NET web service

Hello there,

I've got a .NET web service written in VB using Visual Studio 2003.

I need to change the MIME type for this one web service.

I know I can change it on IIS, but that will change it for all web services (.asmx files) but I don't want to do that, I need to only change it (programatically) for this one web service.

Any ideas?

Cheers
Mike
Avatar of DreamMaster
DreamMaster

Hi bealem,

You can set the mimetype on each page in your application by doing the following:

<%@ Page Language="VB" ContentType="application/xhtml+xml" %>

Where application/xhtml+xml would be changed to whatever mimetype you need.

Regards,
Max.
Avatar of bealem

ASKER

Hi Max,
Thanks for your response.

Yes, I understand I can do that for ASP.NET web pages (.aspx files) but this is a web service (.asmx files)
There is no "html page" code for a web service, only the "code behind" vb code.

Where would I put your example in the .asmx file?

Mike
ASKER CERTIFIED SOLUTION
Avatar of DreamMaster
DreamMaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
bealem,

In essence it means you need to set Response.ContentType to whatever you need.

Regards,
Max.
Glad to have been helpful :)

Regards,
Max.
Avatar of bealem

ASKER

Max,
That link you provided got me going in the right direction.

I was trying to add the Context.Response. commands to my function in my web service, but it wouldn't work, would return what I wanted, then the XML for the web service!

I managed to get round it by changing the functon to a sub:
<WebMethod()> _
Public Sub Something(ByVal strLocation As String)
and replacing the rertrun from the end of the original function to this:
Context.Response.ClearHeaders()
Context.Response.ContentType = "application/*+xml"
Context.Response.Write(strbXML.ToString)

Thanks for you help in getting me going in the right direction.

Cheers
Mike