【问题标题】:How to store the web response in global.asax so that i can use this response from my wcf rest service using C#如何将 Web 响应存储在 global.asax 中,以便我可以使用 C# 从我的 wcf 休息服务中使用此响应
【发布时间】:2016-02-01 13:33:56
【问题描述】:

我正在尝试为我创建的项目创建这个 global.aspx

<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
         var jsoniff = String.Empty;
        string fileName = www.abcd/xyc.com
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileName);
        request.Proxy = null;
        request.Method = "GET";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);
        jsoniff = reader.ReadToEnd();

    }

    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }

</script>

现在,每当我进行新构建或重新启动此项目时,都会执行此 global.asax。
在上面的脚本中,我添加了一个 Application_Start,其中包括一个名为 URl 并读取 JSON 响应以结束。现在我需要在我的 WCF REST 服务中使用这个 jsoniff。
我需要如何在我的 REST 服务中调用 jsoniff 以及上述实现是否正确。
提前致谢

【问题讨论】:

    标签: c# json visual-studio global-asax


    【解决方案1】:

    为什么不使用 AJAX?这将更适合客户端编程。

    【讨论】:

    • 我希望可以。目前我只能使用 global.asax 。所以我需要继续使用上述方法
    猜你喜欢
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多