【问题标题】:How to pass the parameters to WCF Web Service with special characters?如何使用特殊字符将参数传递给 WCF Web 服务?
【发布时间】:2016-03-11 11:10:43
【问题描述】:

我正在使用带有 C# 的 WCF。

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

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

工作

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

不工作

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

【问题讨论】:

  • 你需要HTMLEncode这些字符。

标签: c# web-services wcf wcf-data-services wcf-binding


【解决方案1】:

您应该通过Html encoding发送参数部分:

var safeEmailParam = WebUtility.HtmlEncode(yourEMailParam);

【讨论】:

  • 执行相同操作后,我得到错误 405 Method Not Allowed。
  • @RamBodake 我们无法猜测您可能做了什么。发布您的代码。
  • 这是操作合同- [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);
  • @RamBodake 请编辑您的原始问题并发布minimal reproducible example
  • LoginRequest 方法如下- 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 = "需要用户名和密码。"; } 返回字符串结果; }
【解决方案2】:

检查CDATA下面的链接希望它有帮助

CDATA

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
  • 2011-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多