首页 文章

如何使用特殊字符将参数传递给WCF Web服务?

提问于
浏览
1

我正在使用WCF和C# .

我必须使用特殊字符(例如Email-ram@gmail.com和Password-Test @ 123)将参数传递给WCF Web服务

传递参数时,得到错误“404 Not Found”,如果传递的参数没有特殊字符,则它正在工作 .

Working

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

Not Working

localhost:35798/RestServiceImpl.svc/LoginRequest/ram@gmail.com/Test@123/1223

可能吗?

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

2 回答

  • 3

    您应该通过Html encoding发送作为参数的零件:

    var safeEmailParam = WebUtility.HtmlEncode(yourEMailParam);
    
  • 0

    检查 CDATA 以下链接希望它有所帮助

    CDATA

相关问题