Passing path as String to WCF Service returns null RRS feed

  • Question

  • Hi All,

    This is really strange to me as I have no clue on how to get this fixed.
    I am just passing a path as a string input parameter to my WCF method and it only recognizes the path if I pass it with double slash

    Inpput C:\sample.xls
    passes null value to the string

    Bug if i use below
    it returns

    What I want to achieve is I pass this
    c:\sample.xls and it should take the same value without \\ in the string

    Even this is repro with the default WCF service application template. Create a new Project > WCF Service Application
    Run the WCF service in the second method that accepts string as input pass the path as a sstring and see the return values.

    Monday, August 5, 2013 2:06 PM

All replies

  • Hi newbiems,

    Can you please use verbatim string literal. If you are passing data to the method, you should call like

    string _path = @"c:\sample.xls"

    If it doesn't solve, can you please post your code here.


    Monday, August 5, 2013 2:27 PM
  • Hi,

    As @DE,Subhendu said, in C#, back slash need to be escaped if occured in string literal.

    For example:

    var str = "C:\\sample.xls";

    or we can use

    var str = @"C:\sample.xls";

    For more information, please try to refer to the following article:

    #Escape Sequences: .

    Best Regards.

    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 6, 2013 7:33 AM
  • Hi Subhendu/Amy,

    Well I dont think that would solve my issue. We are passing the path as a parameter from an application. The application reads the path from a DB column and then passes it as a parameter to the webservice. So in this case the below path is stored in the DB column and will be passed to the webservice as a parameter. My WCF service wouldnt recognize it and would take it as null.


    It will recognize it as a path only if I pass as below


    So we need to additionally write code to convert the URL as below and then pass it??
    Much to my surprise is we had an earlier webservice (asmx) with same code recognizing strings as they are without additional conversion. Why is it a problem with just WCF?

    Tuesday, August 6, 2013 9:59 AM
  • Any comments please?
    Wednesday, August 7, 2013 8:54 AM
  • Hi newbiems,

    Can you please send us the code snippet for following part from your application

    "reads the path from a DB column and then passes it as a parameter to the webservice."


    Wednesday, August 7, 2013 9:23 AM