I’m picking up a prototype that my coworker built. I’m a total noob with C# and web services unfortunately. One method in the service is like:
[WebGet(UriTemplate = "GetTestData/{file}")]
public Stream GetTestData(string file)
{
string fileName =
"\\filePath" + file;
if (File.Exists(fileName))
{
FileStream stream = File.OpenRead(fileName);
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "text/.txt";
}
return stream;
}
return null;
}
When I type in the URL from my device like
http://filepath/myFile1.txt
then I get myFile1.txt. She said it was a rest service. Is there an easy way to add headers to this so I can just send the device all the data at once?
Like on the device I can ask for
http://filePath/myFiles
and get myFile1-myFile5.txt? Right now, the crude implementation is I have to ask for each file individually. It would seem better to have the server responsible for sending the packets right? Or is that breaking her rest service? Thanks!
I’m not too sure what you mean here, I think a little bit more context would help. If the client (device) is capable of accepting a response containing multiple files and this is a common use case then sure, the rest resource can return multiple files. For example, you can implement an additional resource for:
http://filePath/myFileslike so:Also, in the sample you provided, to be more RESTful, the Content-Type should be “text/plain” not “text/.txt” and instead of returning null when file isn’t found an WebException with 404 status code should be raised.