摘要
如何在Web服务中创建HTTPContext?或从Web服务POST到Handler.ashx?
背景
我有一个使用表单身份验证的Cold Fusion Web应用程序,但以某种方式使用此脚本实现Windows身份验证:
<cfscript>
ws = CreateObject("webservice", "#qTrim.webServiceName#");
ws.setUsername("#qTrim.trimAcct#");
ws.setPassword("#qTrim.trimpwd#");
wsString=ws.UploadFileCF("#qTrim.webserviceurl#","#objBinaryData#", "#qFiles.Filename#", "Document", "#MetaData#");
</cfscript>
我的问题 现在,这个ColdFusion应用程序需要使用此Web服务下载文件。当CF代码将HTML表单发布到DownloadHandler.ashx时,它可以工作 - 但是只有CF测试者使用这个Windows域帐户。这在生产中不起作用,因为CF应用程序通过表单身份验证支持远程匿名用户。
问题
我自己不了解ColdFusion,我正在考虑以下变化:
复制上述CF技术,使user / pswd可以设置为相同,并让CF直接调用ws.DownloadFile方法
我认为这需要在我的webservice中使用我当前的大部分HTTPHandler代码,但我想不出如何处理输出。当这个处理程序被POST时,它会提示OPEN或Save并且工作得很好,但是我对如何从webservice本身传回来感到困惑。
当前的DownloadFile webmethod与数据库产品通信并将输出返回给此(当前)处理程序:
代码
namespace WebClient
{
public class DownloadHandler : IHttpHandler
{
ASMXproxy.FileService brokerService;
public void ProcessRequest(HttpContext context)
{
brokerService = new ASMXproxy.FileService();
string recNumber = context.Request.Form["txtRecordNumber"];
brokerService.Url = context.Request.Form["txtURL"];
string trimURL = context.Request.Form["txtFakeURLParm"]; // not a real URL but parms to connect to TRIM
brokerService.Timeout = 9999999;
brokerService.Credentials = System.Net.CredentialCache.DefaultCredentials;
byte[] docContent;
string fileType;
string fileName;
string msgInfo = brokerService.DownloadFile(trimURL, recNumber, out docContent, out fileType, out fileName);
string ContentType = MIMEType.MimeType(fileType);
context.Response.AppendHeader("Content-Length", docContent.Length.ToString());
context.Response.AppendHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");
context.Response.ContentType = ContentType;
context.Response.OutputStream.Write(docContent, 0, docContent.Length);
context.Response.OutputStream.Flush();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
答案 0 :(得分:0)
假设您的CF站点在IIS而不是Apache或其他Web服务器上运行,这可能有效:
将调用webservice的.cfm文件放入您网站上自己的子文件夹中。将该文件夹的身份验证属性设置为使用匿名身份验证,但将用户身份设置为成功调用Web服务的Windows域帐户(单击下面显示的对话框上的设置...按钮并输入相应的凭据)。