【发布时间】:2016-08-17 14:45:54
【问题描述】:
我确实有一个 WCF RESTful .NET 4.0 服务,它运行并使用来自 URI 正文的值 #Json。
我调用我的方法的方式如下:
使用海报,作为 POST 请求 http://localhost:25512/JSONService1.svc/CreateItem
主体:
= YOLO
工作正常!
但我也想使用 uri,
http://localhost:25512/JSONService1.svc/CreateItem?uid=aaa&pass=111
这是我的代码
这是在 Service1.cs 上
[OperationContract]
[WebInvoke(UriTemplate = "CreateItem", // ISSUES <<< not sure what to do here
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, Method = "POST")]
void CreateItem(Stream streamOfData,string uid, string pass);
还有与之相关的代码,Service1.svc.cs
public void CreateItem(Stream streamOfData, string uid, string pass)
{
StreamReader reader = new StreamReader(streamOfData);
String res = reader.ReadToEnd();
NameValueCollection coll = HttpUtility.ParseQueryString(res);
}
【问题讨论】:
-
“我也想使用 uri”是什么意思?
-
也许我应该叫它 URL 而不是 URI ,我想传递/使用“uid and pass”参数并在 CreateItem 方法中使用它们
-
好的,所以你想知道客户端发送请求时实际的 URI 是什么?
-
设备“客户端”将始终发送以“?uid=aaa&pass=111”结尾的请求,包括正文中的 JSON。但是,我到目前为止的项目只接受身体。
-
知道了。所以我的问题是,你想知道完整的 URI 是什么吗?