开发者

I have a question about URI templates in WCF Services

开发者 https://www.devze.com 2023-01-03 00:18 出处:网络
I have a web service with following operation contract and my service is hosted at http://localhost:9002/Service.svc/

I have a web service with following operation contract and my service is hosted at http://localhost:9002/Service.svc/

[OperationContract]
[WebGet(UriTemplate = "/Files/{Filepath}")]
Stream DownloadFile(string Filepath);

This web service would let users download file, if the proper filepath is provided (assuming, I somehow find out that proper filepath).

Now, I can access this service from a browser by typing, http://localhost:9002/Service.svc/Files/(Filepath}

If {filepath} is some simple string, its not a problem, but I want to send the location of the file. Lets us say users want to download file C:\Test.mp3 on the server. But how can I pass C:\Test.mp3 as {Filepath}? I get an error when I type http://localhost:开发者_如何学C9002/Service.svc/Files/C:\Test.mp3 in the browser.

I am new to web services and find that this community is the quickest way to get answers to my questions.

got it working now. need to use HttpServerUtility.UrlTokenDecode() from System.web


You cannot type special characters like ":" and "\" as part of a URL. They will need to be URL encoded.


Sounds like you need to URL encode the string, then decode on the back end. Add System.Web to your project and use System.Web.HttpUtility.UrlEncode() then System.Web.HttpUtility.UrlDecode()

0

精彩评论

暂无评论...
验证码 换一张
取 消