1

I'm using WCF with C#.

I have to pass the parameters to WCF web service with special characters like- Email-ram@gmail.com 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/ram@gmail.com/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;
}
LeoFraietta
  • 165
  • 3
  • 11
Ram
  • 133
  • 10

2 Answers2

3

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

var safeEmailParam = WebUtility.HtmlEncode(yourEMailParam);
nvoigt
  • 61,531
  • 23
  • 73
  • 116
  • After doing the same, I got the error 405 Method Not Allowed. – Ram Mar 11 '16 at 13:05
  • @RamBodake We cannot guess what you may have done. Post your code. – nvoigt Mar 11 '16 at 13:06
  • **This is Operation Contract-** [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); – Ram Mar 11 '16 at 13:13
  • @RamBodake Please edit your original question and post a [mcve]. – nvoigt Mar 11 '16 at 13:14
  • **LoginRequest Method as below-** 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; } – Ram Mar 11 '16 at 13:17
  • @RamBodake Where do you use `WebUtility.HtmlEncode` in your code? – nvoigt Mar 11 '16 at 13:46
  • While I'm sending I'd converted it and **URL** like this- localhost:35798/RestServiceImpl.svc/LoginRequest/rambodake18%40gmail.com.com/Test%40123/Test – Ram Mar 11 '16 at 14:01
0

check CDATA below link hope it helps

CDATA

Soner
  • 1,220
  • 3
  • 14
  • 37