【问题标题】:How does one get the method name from a WCF Request in Application_BeginRequest?如何从 Application_BeginRequest 中的 WCF 请求中获取方法名称?
【发布时间】:2016-08-26 20:20:43
【问题描述】:

我在 IIS 中托管 WCF,在我的 HttpApplication 中,我想在 Application_BeginRequest 方法中获取 WCF 操作合同名称(被调用的方法):

protected void Application_BeginRequest(object sender, EventArgs e)
{
    var request = Context.Request;
}

我从上下文中获取请求,但我无法理解如何找到被调用的 WCF 方法的名称。

【问题讨论】:

    标签: c# .net wcf iis


    【解决方案1】:

    查看传入的 HTTP 标头:

    Console.WriteLine(HttpContext.Current.Request.Headers["SOAPAction"]);

    这将吐出完整的价值,在我的示例中是:

    http://tempuri.org/IService1/DoWork

    可能值得注意,但是OperationContext.Current.IncomingMessageHeaders.ActionApplication_BeginRequest中不起作用,因为操作还没有开始,所以OperationContext.Current为空。

    【讨论】:

      【解决方案2】:

      如果这是一个 SOAP WCF 服务,您可以检查项目中的服务引用并查看引用。如果它是 SOAP WCF 并且您尚未将其添加为服务引用,请右键单击该项目并转到添加服务引用。然后添加您希望使用的 url 和命名空间。您还可以导航到 WISDL 以查看那里的方法。为此,您可以在浏览器中以这种格式 http://{WebServiceUrl}/{NameOfService}.svc?wsdl

      提取 url

      如果这是一个 REST WCF 服务,那么该服务可能会提供一个 API 参考。例如,该 url 可能类似于 http://{WebServiceUrl}/{NameOfService}/API/help

      【讨论】:

        猜你喜欢
        • 2019-01-07
        • 1970-01-01
        • 1970-01-01
        • 2020-10-02
        • 2022-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多