Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've implemented a self-hosted local web server using WCF as per this article: Developing Web 2.0 User Interface for Self Hosted WCF Services using HTML5, CSS3 and JQuery

In real world applications, I've found that I needed to make the following modifications in order to handle deeper pathing to sub-folders. This works for my current needs because I simply created enough UriTemplates to get 6 folders deep. However, I suspect there must be a more elegant way to handle this that will allow any number of sub-folders to be served.

I tried to figure something out with wildcards (e.g. /{*path}/{resource}.{extension}) but it seems wildcards are only permitted in the last segment of the path.

Any help would be appreciated,

Ken

[OperationContract, WebGet(UriTemplate = "/{path}/{resource}.{extension}")]
Stream Links(string path, string resource, string extension);

[OperationContract, WebGet(UriTemplate = "/{path1}/{path2}/{resource}.{extension}")]
Stream Links2(string path1, string path2, string resource, string extension);

[OperationContract, WebGet(UriTemplate = "/{path1}/{path2}/{path3}/{resource}.{extension}")]
Stream Links3(string path1, string path2, string path3, string resource, string extension);

[OperationContract, WebGet(UriTemplate = "/{path1}/{path2}/{path3}/{path4}/{resource}.{extension}")]
Stream Links4(string path1, string path2, string path3, string path4, string resource, string extension);

[OperationContract, WebGet(UriTemplate = "/{path1}/{path2}/{path3}/{path4}/{path5}/{resource}.{extension}")]
Stream Links5(string path1, string path2, string path3, string path4, string path5, string resource, string extension);

[OperationContract, WebGet(UriTemplate = "/{path1}/{path2}/{path3}/{path4}/{path5}/{path6}/{resource}.{extension}")]
Stream Links6(string path1, string path2, string path3, string path4, string path5, string path6, string resource, string extension);


public Stream Links(string path, string resource, string extension) {
    return ...;
}

public Stream Links2(string path1, string path2, string resource, string extension) {
    return Links(Path.Combine(path1, path2), resource, extension);
}

public Stream Links3(string path1, string path2, string path3, string resource, string extension) {
    return Links(Path.Combine(path1, path2, path3), resource, extension);
}

public Stream Links4(string path1, string path2, string path3, string path4, string resource, string extension) {
    return Links(Path.Combine(path1, path2, path3, path4), resource, extension);
}

public Stream Links5(string path1, string path2, string path3, string path4, string path5, string resource, string extension) {
    return Links(Path.Combine(path1, path2, path3, path4, path5), resource, extension);
}

public Stream Links6(string path1, string path2, string path3, string path4, string path5, string path6, string resource, string extension) {
    return Links(Path.Combine(path1, path2, path3, path4, path5, path6), resource, extension);
}
Posted

1 solution

Why not just use something like this...

[OperationContract]
[WebGet(UriTemplate = "{*pathname}")]
public Stream Links(string pathname)
{
    string path = Path.GetDirectoryName(pathname);
    string resource = Path.GetFileNameWithoutExtension(pathname);
    string extension = Path.GetExtension(pathname).TrimStart('.');
    return Links(path, resource, extension);
}
 
Share this answer
 
v7
Comments
lynchpi 19-Mar-14 13:15pm    
I use [WebGet(UriTemplate = "{*pathname}")] test myself.

And the url='http://localhost:50923/OMSService.svc/Links?seller=s001&service=s2&timstamp=324&user=uo&pass=009',

and then why the pathname='Links'.It means that the pathname is the called method name ,

is not the long string 'seller=s001&service=s2&timstamp=324&user=uo&pass=009'!

Thanks in advance !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900