0
有一個WCF服務在C#中:從繼承的類設置響應格式的HTML郵件
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
class SubscriptionService : ISubscriptionService
{
public Message Help(Message m)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html; charset=utf-8";
return new WebHttpHelpPageMessage();
}
}
[ServiceContract]
interface ISubscriptionService
{
[OperationContract]
[WebInvoke(UriTemplate = "*", Method = "*")]
Message Help(Message m);
}
消息:
public class WebHttpHelpPageMessage : Message
{
...
protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer)
{
writer.WriteStartElement("html");
writer.WriteRaw("<head></head><body><p>Hi</p></body>");
writer.WriteEndElement();
}
}
在瀏覽器中的結果 - XML,如何做它是HTML?
它不那麼清楚你的要求,但你是說,你瀏覽器顯示XML,而你想顯示HTML? – Bravo11
是的,那content-type =「text/html」 – ask125342