# .NET and More > WPF, WCF, WF >  Passing a filepath to a web service  - Problem

## kumika

I am trying to pass a string: c:\Books\image.jpg to a web service with no success. I tried to encode it as: <Code> returnString = HttpUtility.UriEncode(pathString)</Code>

The encoding works fine but I still get the Error 400 (Bad request). I get the same error if I pass a string with a dot such  :Frown: This is not good.)  But if I remove the dot, the request goes through.  What causes the error and how do we solve? The encoding does not seem to work. Thanks for helping.

----------


## kumika

I see noone is keen to assist me here. I decided to encode and strip the path
of these special characters, transferred it across to the server and re-assembled or replaced the characters again. This works but I feel there is a better way to do it. I tried putting  the validateRequest = "false" property in the web.config file, but it did not help. If you know of a better solution, please post it. Thanks




> I am trying to pass a string: c:\Books\image.jpg to a web service with no success. I tried to encode it as: <Code> returnString = HttpUtility.UriEncode(pathString)</Code>
> 
> The encoding works fine but I still get the Error 400 (Bad request). I get the same error if I pass a string with a dot such This is not good.)  But if I remove the dot, the request goes through.  What causes the error and how do we solve? The encoding does not seem to work. Thanks for helping.

----------


## szlamany

Show some code where you are doing this - I pass all kinds of characters to web services with little issue.

----------


## kumika

Well like I said in my starter post, I want to pass a file path variable to a web service and I constantly get the 400 Bad Request error message. The reason is that the string has the special/security sensitive characters. For example, the string is: C:\Books\myImage.jpg. Now I want to know how to set up the web.config file to allow these characters access without causing security problems. I tried using the validateRequest = "false" with no success. Please be clear where I can insert the tags in the configuration files. Some posts are ambiguous to understand. I see we can also use the requestPathInvalidCharacters property but I can't find it in the web.config file. I use .net 4. Framework. Thanks for helping.




> Show some code where you are doing this - I pass all kinds of characters to web services with little issue.

----------


## szlamany

You can't specify a path like that on the remote web server to get to.

All paths are connected to - sub folders of - the root directory hosting the web files.

When you say "pass a file path variable to a web service" how are you doing that?

Typing it into the ADDRESS bar of a browser page?

Calling it from some JavaScript code?

In some WCF markup file??

----------


## kumika

I pass as an argument in the query string in the WCF Client page code behind as follows: 

<Code>"http://localhost:4000/appName/" _
& "Service.svc/className/" & filePath))
</Code>

filePath = C:\Books\myImage.jpg. The special characters in this string cause the 400 error. Thanks




> You can't specify a path like that on the remote web server to get to.
> 
> All paths are connected to - sub folders of - the root directory hosting the web files.
> 
> When you say "pass a file path variable to a web service" how are you doing that?
> 
> Typing it into the ADDRESS bar of a browser page?
> 
> Calling it from some JavaScript code?
> ...

----------


## techgnome

what does the service do?

meaning that it depends on what the service does with the string you're sending it. 

-tg

----------


## kumika

The service simply saves the data/string in the database. It pulls it out and send it back on request by the client.




> what does the service do?
> 
> meaning that it depends on what the service does with the string you're sending it. 
> 
> -tg

----------


## szlamany

You are trying to pass that as the QUERY STRING value in the URL - right?

That needs to be properly encoded.  Something I do not do myself (I am all AJAX with JSON POSTS).

----------

