在javascript中处理响应对象

时间:2014-06-05 15:23:06

标签: javascript asp.net .net wcf asp-classic

我有一个ASP.NET Web应用程序和一个经典ASP页面,它调用WCF服务并获得一个复合类型R作为响应。

ASP.NET Web应用程序获取复合对象(R)并执行以下操作:

if(R.IsValid)
{
                Response.Clear();
                Response.ContentType = contentType;
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName));
                Response.AddHeader("Content-Length", R.ByteArray.Length.ToString());
                Response.BinaryWrite(R.ByteArray);
                Response.End();
}

经典ASP页面也得到了响应。

  1. 如何将其强制转换为复合类型R(使用IsValid和ByteArray)?
  2. 如何使用javascript中的ServerXMLHTTP对象执行可以在.NET中执行Response对象的操作?
  3. 更新:

    function CallWcfAjax()
        {
            var xmlHttp = new ActiveXObject("Microsoft.XmlHttp");
    
           var url = "http://localhost:54329/DocumentGeneratorService.svc/ajaxEndpoint/";
            url = url + "GetDetailsMessageUsingPost";
    
          var xmlContents = loadXML("Data.xml");
    
           var getDetailsMessageUsingPostBody = '<GetDetailsMessageUsingPost><input>';
            getDetailsMessageUsingPostBody = getDetailsMessageUsingPostBody + xmlContents;
            getDetailsMessageUsingPostBody = getDetailsMessageUsingPostBody + '</input></GetDetailsMessageUsingPost>';
    
            // Send the HTTP request
            xmlHttp.open("POST", url, true);
            xmlHttp.setRequestHeader("Content-type", "text/xml; charset=utf-8");
            xmlHttp.send(getDetailsMessageUsingPostBody);
    
            // Create result handler 
            xmlHttp.onreadystatechange= function X()
            {        
                if (xmlHttp.readyState == 4)
                {
                    result.innerText = xmlHttp.responseText;
                    // TODO: Handle xmlHttp.responseStream or other property
                 }
            }
        }
    

0 个答案:

没有答案