我用 Http WebRequest 调用我的 WCF WebService。它工作正常,但是当我在参数中传递一些特殊字符时,它会给出错误 404。找不到页面..
这是我的代码片段。
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Data/{username}/{password}")]
string RequestData(string userName, string password);
public string RequestData(string userName, string password)
{
// Here is My Logic Comes
}
// Here im Calling This Service in My ASPX Page
HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
const string url = "http://localhost:53366/AuthService.svc/Data/test@test.com/password#1"; // Here Gives Error 404 Page Not Found
//const string url = "http://localhost:53366/AuthService.svc/Data/test/password"; // Here Works Fine When I Pass This Paramters Without Special Characters
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "Get";
req.ContentType = "application/json; charset=utf-8";
req.Headers.Add("AppID", "MobileApplication");
res = (HttpWebResponse)req.GetResponse();
Stream responseStream = res.GetResponseStream();
var streamReader = new StreamReader(responseStream);
txtTokenRespoonse.Text = streamReader.ReadToEnd();
streamReader.Close();
streamReader.Dispose();
responseStream.Close();
responseStream.Dispose();
}