本文介绍了寻求通过WebMethod传输文件的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 到目前为止,我们的应用程序一直在使用Windows文件共享来向我们的应用程序文档存储库传输文件。这种 方法不适合安全的环境,所以我们在我们的应用程序客户端之间强加WebService网关的过程中 (作为起点,WebService不是一个功能丰富的应用程序 服务器;业务规则仍然在但是这将确保所有对文档存储库的访问都是通过我们的软件进行的。 虽然下面的WebMethod只接受一个参数,但我很快就会 要为此方法添加身份验证参数,以确保对此WebMethod的访问实际上来自我们的客户端应用程序。) 这是我定义的方法(下面)。我有两个问题,一个是与功能有关的,另一个是与性能有关的问题。 1.我无法解决这个问题!当我测试这个时,我收到以下错误 消息: 无法打开C:\ Winzip.log - >访问路径 & quot; C:\ Winzip.log& quot;被拒绝。 这里是发生异常的代码行: FileStream FS =新FileStream(FileSpec,FileMode) 。打开); 我无法想象这是一个Windows安全问题。我有匿名 访问禁用,集成Windows身份验证启用,因此请求 必须使用我的凭据运行,我能够通过 Windows shell。我想也许我需要在某个地方调整一个设置, 但是我不知道在哪里。 2.这是最简单的流式传输方式一个文件回到远程客户端?快速 将文档交付给客户是至关重要的,因此我可以做的任何改善性能的事情对我来说都很重要。也许转换为 Base64String效率不高?如果我可以使用更高效的格式,我将支付。请记住,我需要将二进制文件(例如JPG)流式传输为 以及文本,因此我需要一种能够保留每一位的格式,因为它可以通过HTTP。 非常感谢您的建议! - Joe Geretz - [ WebMethod] public string GetFileStream(string FileSpec) { try { FileStream FS = new FileStream(FileSpec,FileMode.Open); byte [] FileBytes = new byte [FS.Length]; FS.Read(FileBytes, 0,(int)FS.Length); FS.Close(); 返回System.Convert.ToBase64String(FileBytes,0,FileBytes.Length); } catch(例外e) { 抛出新异常(无法打开+ FileSpec ,e); } } 解决方案 要通过SOAP传输文件,请查看Microsoft WSE和 它实现的SOAP附件规范。 干杯 Jimbo。 这个文件是客户端的文件系统还是服务器的文件? 为什么不要你只是使用Windows SharePoint Services。它是操作系统的一部分, 这就是它的用途。 David 这个文件是客户端的文件系统还是服务器的文件? 为什么不使用Windows SharePoint?服务。它是操作系统的一部分,这就是它的用途。 David Up to this point, our application has been using Windows File Sharing totransfer files to and from our application document repository. Thisapproach does not lend itself toward a secure environment and so we are inthe process of imposing a WebService gateway between our application clientand the repository.(As a starting point, the WebService won''t be a richly featured applicationserver; business rules are still implemented in the client. But this willensure that all access to the document repository is made via our software.Although the WebMethod below accepts only a single parameter, I''ll shortlybe adding authentication parameters to this method to ensure that accessesto this WebMethod actually originate from our client application.)Here is the method which I''ve defined (below). I have two questions, onewhich relates to functionality, and the other which relates to performance.1. I can''t get this to work! When I test this I get the following errormessage:Could not open C:\Winzip.log --> Access to the path"C:\Winzip.log" is denied.Here''s the line of code on which the exception occurs:FileStream FS = new FileStream(FileSpec, FileMode.Open);I can''t imagine that this is a Windows security problem. I have anonymousaccess disabled, integrated Windows authentication enabled, so the requestmust be running using my credentials and I''m able to open this file via theWindows shell. I imagine that perhaps I need to tweak a setting somewhere,but I''m not sure where.2. Is this the quickest way to stream a file back to a remote client? Speedydelivery of the document to the client is critical and so anything that Ican do to improve performance is important to me. Maybe conversion toBase64String is not as efficient? If I can use a more efficient format Iwill. Just bear in mind that I need to stream binary files (e.g. JPG) aswell as textual, so I need a format which will preserve every bit as ittravels via HTTP.Thanks very much for your advice!- Joe Geretz -[WebMethod]public string GetFileStream(string FileSpec){try{FileStream FS = new FileStream(FileSpec, FileMode.Open);byte[] FileBytes = new byte[FS.Length];FS.Read(FileBytes, 0, (int)FS.Length);FS.Close();return System.Convert.ToBase64String(FileBytes, 0, FileBytes.Length);}catch (Exception e){throw new Exception("Could not open " + FileSpec, e);}} 解决方案For transferring a file via SOAP take a look at the Microsoft WSE andthe SOAP Attachments specification it implements.CheersJimbo.Is this file on the Client''s filesystem or the Server''s?Why don''t you just use Windows SharePoint Services. It''s part of the OS,and that''s what it''s for.David Is this file on the Client''s filesystem or the Server''s? Why don''t you just use Windows SharePoint Services. It''s part of the OS, and that''s what it''s for. David 这篇关于寻求通过WebMethod传输文件的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-19 08:14