處理404我有IIS 7.5 WCF休息服務。當用戶訪問不存在(即http://localhost/rest.svc/DOESNOTEXIST VS http://localhost/EXISTS),他們都帶有一個通用WCF灰色和藍色的錯誤頁面的狀態代碼:404。然而端點的一部分,我想回類似以下內容:在WCF REST服務
<service-response>
<error>The url requested does not exist</error>
</service-response>
我嘗試在IIS中配置自定義錯誤,但只有在請求其餘服務之外的頁面(例如http://localhost/DOESNOTEXIST)時才能工作。
有誰知道如何做到這一點?
編輯 後低於我的答案是能找出我需要創建一個實現BehaviorExtensionElement一個WebHttpExceptionBehaviorElement類。
public class WebHttpExceptionBehaviorElement : BehaviorExtensionElement
{
///
/// Get the type of behavior to attach to the endpoint
///
public override Type BehaviorType
{
get
{
return typeof(WebHttpExceptionBehavior);
}
}
///
/// Create the custom behavior
///
protected override object CreateBehavior()
{
return new WebHttpExceptionBehavior();
}
}
當時我能夠通過引用它在我的web.config文件:
<extensions>
<behaviorExtensions>
<add name="customError" type="Service.WebHttpExceptionBehaviorElement, Service"/>
</behaviorExtensions>
</extensions>
,然後加入
<customError />
到我的默認端點的行爲。
感謝,
傑弗裏·凱文撬
您是否使用REST入門套件或WCF Web API?調用部分中的 – 2011-06-16 12:34:52