![](/img/trans.png)
[英]WCF adding additional HTTP header to HTTP response for transporting SOAP message
[英]Restful WCF adding message header to outgoing response
我一直在嘗試將具有值的自定義標頭添加到傳出響應消息中。 每個用戶請求的值都將不同。
但是,我無法使用以下代碼為標頭添加值:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IMyService
{
public string CommandHandler()
{
string s = "test";
WebOperationContext.Current.OutgoingResponse.Headers.Add("testheader", "123456");
return s;
}
}
如果將以下代碼添加到global.asax
,則可以,但是testheader
始終為123
,我無法更改該值。
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET");
HttpContext.Current.Response.AddHeader("testheader", "123");
HttpContext.Current.Response.End();
}
}
始終為123,因為您通過以下方式將其顯式設置為123:
HttpContext.Current.Response.AddHeader("testheader", "123");
以下是有關如何創建端點行為並正確注冊它的示例的鏈接。 MS MVP的WCF博客
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.