我有一个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页面也得到了响应。
更新:
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
}
}
}