c# - WCF 自托管服务,参数(字符串)断言失败
问题描述
我有一个自托管的 wcf 服务,它有三个 OperationContract,其中两个应该接受参数
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "json/{id}")]
string JSONData(string id);
基于这个参数,我执行一些逻辑并返回数据:
public string JSONData(string id)
{
if (id == "1")
{
string json = "{ \"months\":[{ \"name\":\"January\"}, { \"name\":\"Febuary\"}, { \"name\":\"March\"} ]}";
return json;
}
else
{
return "Id not found, invalid request";
}
}
我使用邮递员做这个请求:
但是,我填写的 id 并不重要,我总是得到:
"Id not found, invalid request"
为了增加我的困惑,以下确实有效:
public string JSONData(string id)
{
return Data(id);
}
private string Data(string id)
{
// logic
return "Data: " + id;
}
这让我相信,与其说输入失败不如 if 语句中的断言失败。
将逻辑更改为:
public string JSONData(string id)
{
if (id.Equals("name"))
{
return "equal";
}
else {
return Data(id);
}
}
private string Data(string id)
{
// logic
return "Data: " + id;
}
if 语句中的断言仍未完成,但是我看不出我在以这种方式断言字符串的相等性时做错了什么。
帮助将不胜感激。
谢谢。
解决方案
我不知道您想要完成什么,但使用 wcftestclient 我可以返回您所要求的内容。
推荐阅读
- android - ArCore .obj FileNotFound 异常
- c - 带有 OpenSSL 后端的 libcurl 中的虚假服务器名称指示 (SNI)
- vba - 调试 Levenshtein 距离实现 - 如何计算最小距离?
- java - 重新创建片段后微调器文本变为空白/白色
- java - 我的 java 客户端不适用于我的 python 服务器
- java - 使用firebase android卡在阻止用户彼此之间的功能中
- python - ValueError:发现样本数量不一致的输入变量:[4, 103]
- javascript - 如何解决未捕获(承诺),无法在网络摄像头媒体设备上设置属性“innerHTML”为空
- android - 使用 Google Maps Android API 构建派对应用?
- html - 选定的 div 不应悬停在幻灯片中 [JsFiddle]