【发布时间】:2011-09-06 06:28:21
【问题描述】:
我有一个 RESTful WCF 服务,它的上传方法接受多个参数。它通过使除 URI 的 Stream 部分之外的所有参数来实现这一点。这是合约中方法的样子:
[OperationContract, WebInvoke(UriTemplate = "UploadFile?username={username}&password={password}&filename={filename}")]
bool UploadFile(string username, string password, string filename, Stream fileContents);
我还没有测试过这个方法,但是假设它确实有效,那么它有一个主要问题:密码会在地址栏中显示。如何隐藏这些参数,同时将它们保留为 UriTemplate 的一部分?我需要它们作为 URI 的一部分,因为这允许我在 Stream 中使用其他参数。
这是我尝试做的:
[OperationContract, WebInvoke(Method = "POST", UriTemplate = "UploadFile?username={username}&password={password}&filename={filename}")]
bool UploadFile(string username, string password, string filename, Stream fileContents);
这只是一个疯狂的猜测,我什至不确定它是否有意义。 WCF 服务启动得很好,但我还没有测试它。是否可以通过这种方式在 URI 上使用 HTTP POST?
【问题讨论】: