简体   繁体   中英

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-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;
}

您应该通过Html编码发送作为参数的部分:

var safeEmailParam = WebUtility.HtmlEncode(yourEMailParam);

check CDATA below link hope it helps

CDATA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM