Cross Origin Resource Sharing for c# WCF Restful web service hosted as Windows service

前端 未结 2 809
灰色年华
灰色年华 2020-12-03 09:00

I have a WCF Restful service which I am hosting as Windows service. I want to add cross domain support to my service. However, i can do this easily when I use global.asax fi

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 09:37

    I believe that the closest thing to Application_BeginRequest in the WCF world are Message Inspectors:

    A message inspector is an extensibility object that can be used in the service model's client runtime and dispatch runtime programmatically or through configuration and that can inspect and alter messages after they are received or before they are sent.

    In order to use custom message inspectors you'll have to:

    1. Create a class that implements the IDispatchMessageInspector interface (your custom inspector)
    2. Add the custom inspector to your service's DispatchRuntime.MessageInspectors collection

    Here you can find more info and some sample code on how to do this.

提交回复
热议问题