寻求通过WebMethod传输文件的建议 [英] Seeking advice on transferring a file via WebMethod

查看:72
本文介绍了寻求通过WebMethod传输文件的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我们的应用程序一直在使用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);

}

}

解决方案

Joseph Geretz写道:

到目前为止,我们的应用程序一直在使用Windows File Sharin g将
文件传输到我们的应用程序文档存储库或从我们的应用程这种方法不适合安全环境,因此我们处于在应用程序客户端和存储库之间强加WebService网关的过程中。

(作为一个起点,WebService不是一个功能丰富的应用程序服务器;业务规则仍然在客户端实现。但这将确保所有对文档存储库的访问都是通过我们的软件。
虽然下面的WebMethod只接受一个参数,但我很快就会在这个方法中添加认证参数,以确保对这个WebMethod的访问实际上来自我们的客户端应用程序。 。)

这是我定义的方法(下面)。我有两个问题,一个与功能有关,另一个与性能有关。

1.我无法解决这个问题!当我测试这个时,我收到以下错误
消息:

无法打开C:\ Winzip.log - >访问路径
& quot; C:\ Winzip.log& quot;被拒绝。

这是发生异常的代码行:

FileStream FS = new FileStream(FileSpec,FileMode.Open);

我无法想象这是一个Windows安全问题。我禁用了匿名访问权限,启用了集成Windows身份验证,因此请求必须使用我的凭据运行,并且我可以通过Windows shell打开此文件。我想也许我需要在某个地方调整设置,
但我不知道在哪里。

2.这是将文件流回远程客户端的最快方法吗?快速向客户交付文档至关重要,因此我可以做的任何改善性能的事情对我来说都很重要。也许转换为
Base64String效率不高?如果我可以使用更高效的格式,我将会。请记住,我需要将二进制文件(例如JPG)和文本文件一起流式传输,因此我需要一种能够保留每一位的格式,因为它通过HTTP传播。

- Joe Geretz -

[WebMethod]
公共字符串GetFileStream(string FileSpec)
{
尝试
{/> FileStream FS =新的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。



" Joseph Geretz" < JG ***** @ nospam.com>在消息中写道

news:uJ ************** @ tk2msftngp13.phx.gbl ...

到目前为止,我们的应用程序一直在使用Windows文件共享来向我们的应用程序文档存储库传输文件。这种方法不适用于安全的环境,因此我们处于在应用程序客户端和存储库之间强加WebService网关的过程中。

(作为一个起点,WebService不是一个功能丰富的应用程序服务器;业务规则仍然在客户端实现。
但这将确保对文档存储库的所有访问都是<通过我们的软件。虽然下面的WebMethod只接受一个
参数,但我很快就会在这个方法中添加认证参数
以确保对这个WebMethod的访问实际上来自我们的客户端应用程序。)

这是我定义的方法(如下)。我有两个问题,一个与功能有关,另一个与性能有关。

1.我无法解决这个问题!当我测试这个时,我收到以下错误
消息:

无法打开C:\ Winzip.log - >访问路径
& quot; C:\ Winzip.log& quot;被拒绝。




这个文件是客户端的文件系统还是服务器的文件?


为什么不要你只是使用Windows SharePoint Services。它是操作系统的一部分,

这就是它的用途。


David


大卫

感谢您的回复。


该文件在服务器上。这就是重点,我们将

WebService强加为服务器端文件存储库和

客户端之间的网关。


通过将以下指令放在

Web.config文件中,我可以访问:


< identity impersonate = QUOT;真"的userName = QUOT; SRS\Joseph"密码=" foobar" />


但是,即使我已登录为

SRS \,以下指令也不起作用约瑟夫。


< identity impersonate =" true"的userName = QUOT;"密码="" />


我很好奇为什么后者不起作用。我的网站设置为使用

集成的Windows身份验证。在后一种情况下,交易是否应该使用

凭证SRS \ Joseph,就像在前一种情况下一样?

为什么不要你只是使用Windows SharePoint Services。它是操作系统的一部分,
这就是它的用途。


Sharepoint将其文件存储在SQL Server中。 BLOB访问不像原生文件系统访问那样快。

。如果我们想要走那条路,我们很久以前就已经将文件存储在SQL Server中了。


谢谢,

- Joe Geretz -


" David Browne" < davidbaxterbrowne没有盆栽 me**@hotmail.com >写在

消息新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
Joseph Geretz < JG ***** @ nospam.com>在消息中写道
新闻:uJ ************** @ tk2msftngp13.phx.gbl ...

到目前为止,我们的申请已经使用Windows文件共享来与我们的应用程序文档存储库之间传输文件。这种方法不适用于安全的环境,所以我们在我们的应用程序客户端和存储库之间强加WebService网关的过程中。

(作为一个起点,WebService不是一个功能丰富的应用程序服务器;业务规则仍然在客户端实现。
但这将确保对文档存储库的所有访问都是<通过我们的软件。虽然下面的WebMethod只接受一个
参数,但我很快就会在这个
方法中添加认证参数,以确保对这个WebMethod的访问实际上来自
我们的客户申请。)

这是我定义的方法(如下)。我有两个问题,一个与功能有关,另一个与性能有关。

1.我无法解决这个问题!当我测试这个时,我收到以下错误
消息:

无法打开C:\ Winzip.log - >访问路径
& quot; C:\ Winzip.log& quot;被拒绝。



这个文件是客户端的文件系统还是服务器的文件?

为什么不使用Windows SharePoint?服务。它是操作系统的一部分,
这就是它的用途。

David



Up to this point, our application has been using Windows File Sharing to
transfer files to and from our application document repository. This
approach does not lend itself toward a secure environment and so we are in
the process of imposing a WebService gateway between our application client
and the repository.

(As a starting point, the WebService won''t be a richly featured application
server; business rules are still implemented in the client. But this will
ensure that all access to the document repository is made via our software.
Although the WebMethod below accepts only a single parameter, I''ll shortly
be adding authentication parameters to this method to ensure that accesses
to this WebMethod actually originate from our client application.)

Here is the method which I''ve defined (below). I have two questions, one
which 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 error
message:

Could not open C:\Winzip.log --> Access to the path
&quot;C:\Winzip.log&quot; 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 anonymous
access disabled, integrated Windows authentication enabled, so the request
must be running using my credentials and I''m able to open this file via the
Windows 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? Speedy
delivery of the document to the client is critical and so anything that I
can do to improve performance is important to me. Maybe conversion to
Base64String is not as efficient? If I can use a more efficient format I
will. Just bear in mind that I need to stream binary files (e.g. JPG) as
well as textual, so I need a format which will preserve every bit as it
travels 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);
}
}

解决方案

Joseph Geretz wrote:

Up to this point, our application has been using Windows File Sharing to
transfer files to and from our application document repository. This
approach does not lend itself toward a secure environment and so we are in
the process of imposing a WebService gateway between our application client
and the repository.

(As a starting point, the WebService won''t be a richly featured application
server; business rules are still implemented in the client. But this will
ensure that all access to the document repository is made via our software.
Although the WebMethod below accepts only a single parameter, I''ll shortly
be adding authentication parameters to this method to ensure that accesses
to this WebMethod actually originate from our client application.)

Here is the method which I''ve defined (below). I have two questions, one
which 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 error
message:

Could not open C:\Winzip.log --> Access to the path
&quot;C:\Winzip.log&quot; 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 anonymous
access disabled, integrated Windows authentication enabled, so the request
must be running using my credentials and I''m able to open this file via the
Windows 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? Speedy
delivery of the document to the client is critical and so anything that I
can do to improve performance is important to me. Maybe conversion to
Base64String is not as efficient? If I can use a more efficient format I
will. Just bear in mind that I need to stream binary files (e.g. JPG) as
well as textual, so I need a format which will preserve every bit as it
travels 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 and
the SOAP Attachments specification it implements.

Cheers
Jimbo.



"Joseph Geretz" <jg*****@nospam.com> wrote in message
news:uJ**************@tk2msftngp13.phx.gbl...

Up to this point, our application has been using Windows File Sharing to
transfer files to and from our application document repository. This
approach does not lend itself toward a secure environment and so we are in
the process of imposing a WebService gateway between our application
client and the repository.

(As a starting point, the WebService won''t be a richly featured
application server; business rules are still implemented in the client.
But this will ensure that all access to the document repository is made
via our software. Although the WebMethod below accepts only a single
parameter, I''ll shortly be adding authentication parameters to this method
to ensure that accesses to this WebMethod actually originate from our
client application.)

Here is the method which I''ve defined (below). I have two questions, one
which 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 error
message:

Could not open C:\Winzip.log --> Access to the path
&quot;C:\Winzip.log&quot; is denied.



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


Hi David,

Thanks for your response.

The file is on the server. That''s the whole point, we''re imposing the
WebService as a gateway between the server-side file repository and the
clients.

I am able to get access, by placing the following directive inside the
Web.config file:

<identity impersonate="true" userName="SRS\Joseph" password="foobar"/>

However, the following directive doesn''t work, even though I am logged in as
SRS\Joseph.

<identity impersonate="true" userName="" password=""/>

I''m curious as to why the latter doesn''t work. My site is set up to use
integrated Windows authentication. Shouldn''t the transaction be using the
credentials SRS\Joseph in the latter case, just as it is in the former case?

Why don''t you just use Windows SharePoint Services. It''s part of the OS,
and that''s what it''s for.
Sharepoint stores its files inside SQL Server. BLOB access is not as quick
as native filesystem access. If we wanted to go that route, we''d have been
storing our documents inside SQL Server a long time ago.

Thanks,

- Joe Geretz -

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
"Joseph Geretz" <jg*****@nospam.com> wrote in message
news:uJ**************@tk2msftngp13.phx.gbl...

Up to this point, our application has been using Windows File Sharing to
transfer files to and from our application document repository. This
approach does not lend itself toward a secure environment and so we are
in the process of imposing a WebService gateway between our application
client and the repository.

(As a starting point, the WebService won''t be a richly featured
application server; business rules are still implemented in the client.
But this will ensure that all access to the document repository is made
via our software. Although the WebMethod below accepts only a single
parameter, I''ll shortly be adding authentication parameters to this
method to ensure that accesses to this WebMethod actually originate from
our client application.)

Here is the method which I''ve defined (below). I have two questions, one
which 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 error
message:

Could not open C:\Winzip.log --> Access to the path
&quot;C:\Winzip.log&quot; is denied.



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传输文件的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆