如何在global.asax中存储Web响应,以便我可以使用C#从我的wcf rest服务中使用此响应

时间:2016-02-01 13:33:56

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

我正在尝试为我创建的项目创建此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响应读取到end。现在我需要在我的WCF REST服务中使用这个jsoniff 如何在我的REST服务中调用jsoniff,上述实现是否正确 在此先感谢

1 个答案:

答案 0 :(得分:0)

为什么不使用AJAX?对于客户端编程,这将是更优选的。