Search code examples
c#web-serviceswcfwcf-data-serviceswcf-binding

How to pass the parameters to WCF Web Service with special characters?


I'm using WCF with C#.

I have to pass the parameters to WCF web service with special characters like- [email protected] and Password-Test@123

While passing the parameters, got error "404 Not Found" and if passed parameters without special characters it's working.

Working

localhost:35798/RestServiceImpl.svc/LoginRequest/ram/Test123/1223

Not Working

localhost:35798/RestServiceImpl.svc/LoginRequest/[email protected]/Test@123/1223

Is it possible?

/** Code for the same **/
[OperationContract]
    [WebInvoke( 
    Method = "POST", 
    RequestFormat = WebMessageFormat.Json, 
    ResponseFormat = WebMessageFormat.Json, 
    BodyStyle = WebMessageBodyStyle.WrappedRequest, 
    UriTemplate = "LoginRequest/{Email}/{Password}/{APPUID}")]

string LoginRequest(string Email, string Password, string APPUID);

public string LoginRequest(string Email, string Password, string APPUID)
{
    string strResult = "";
    if (Password.Trim() != null && Password.Trim() != "" && Email.Trim() != null && Email.Trim() != "")
        {
            strResult = " Success.";
        }
    else
        {
            strResult = "User name and password are required.";
        }
    return strResult;
}

Solution

  • You should send the parts that are parameters through Html encoding:

    var safeEmailParam = WebUtility.HtmlEncode(yourEMailParam);