This is just a guess, but you could try something like:
(in your webservice class)
MyBase.Context.Response.Co
Main Topics
Browse All TopicsI have a WebService with a [WebMethod] that returns a custom class. This custom class was generated from my XML scheme using xsd.exe.
The XML that is produced by WebService is correct, however I have one problem:
I need the HTTP ContentType field to be set to "text/xml" instead of "text/xml; charset=utf-8".
Anyone know of a way to do this?
Thank you.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I have tried adding the following in my [WebMethod]
HttpContext.Current.Respon
and this did not work. I even tried:
this.Content.Response.Cont
and that didn't work either.
My guess is that the WebService class is setting the HTTP Content-Type field once the [WebMethod] returns. So, I am thinking that I need to configure the WebService some how? I am not sure how to do this?
I don't have a webpage per say. I access the WebService directly. For instance, I use the following URL:
http://SERVER_IP/TestWebSe
This produces the XML. Without going into too much detail, The TestMethod method would acctually be doing some DB operations. Then it would result in XML. However, the HTTP Context-Type is "text/xml; charset=utf-8" and I only want "text/xml'. Therefore, I can't use any ASP.NET as I do not use an *.aspx front-end.
So, I am looking for a way to configure the HTTP Content-Type the TestWebService.asmx returns. Perhaps it is some magical setting in Web.Config or something? I mean, what is generating the XML when the 'return' statement is executed in TestMethod??
When I look at the WSDL for the WebService it describes what the HTTP-GET returns.
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<rootTag xmlns="http://tempuri.org/
<field1>string</field1>
<subfield1>
<field2>string</field2>
</subfield1>
<subfield2>
<field2>string</field2>
</subfield>
</rootTag>
Now, it looks like the something is generating the XML outside of the WebMethod "Test3". So, I think that any configuration inside the method gets over-written. Anyone know what this is?
I think I am a little closer to a solution. What I did was create the following ASP.NET page with the following Page_Load method:
private void Page_Load(object sender, System.EventArgs e)
{
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.ContentEncoding = new MyEncoding();
Response.ContentType = "text/xml";
Response.Write("<rootTag>"
Response.Write("<Title>Fro
Response.Write("<Menu><Nam
Response.Write("<URL>http:
Response.Write("</rootTag >");
}
The MyEncoding class inherits from UTF8Encoding. The only method overriden is the WebName method. It returns the empty string.
The resulting HTTP Content-Type field is now: "text/xml".
Now I am trying to get the XML produced from my WebMethod and return that from my ASP.NET page. However, my WebMethod returns an object and not the XML.
How do I capture the XML produced from a WebMethod?
Try doing the serialization yourself and not returning the object (this does some automatic serialization in the background perhaps out of scope)
In your method try doing this instead of returning somthing.
YourNamespace.YourObject yo = new YourNamespace.YourObject()
XmlSerializer xs = new XmlSerializer(typeof(YourN
this.Context.Response.Cont
XmlTextWriter writer = new XmlTextWriter(this.Context
xs.Serialize(writer,yo);
cheers,
ProgGuy2
Business Accounts
Answer for Membership
by: mehtasPosted on 2003-05-30 at 14:20:13ID: 8617335
Did you try to use a property ContentType and set it to "text/xml"?
Siddhartha