c# - 如何在 WCF Rest Service 中传递多个参数:C# 中的字符串和流
问题描述
我有一个 WCf 休息服务,它有两个输入参数:字符串和流:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "ImportStream/{Separator}", ResponseFormat =
WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
void ImportStream(string Separator, stream data);
我的代码:
public void ImportStream (string Separator, Stream inputpar)
{ //...
}
我的目标是使用 POSTMAN 调用服务: https://localhost:44355/ServiceLias.svc/rest/ImportStream/Comma
在正文中,我将 Stream 写为 Text ,
但我从一开始就有错误:
For request in operation ImportStream to be a stream the operation must have a single parameter whose type is Stream.
我该如何解决?或者有什么想法可以实现我的目标?谢谢,
解决方案
函数签名的定义不符合在 WCF 中启用流数据的规则。它违反了以下定义。
保存要流式传输的数据的参数必须是方法中的唯一参数。例如,如果输入消息是要流式传输的消息,则操作必须只有一个输入参数。类似地,如果要流式传输输出消息,则操作必须只有一个输出参数或返回值。
Streaming的开启方法请参考官方文档。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-enable-streaming
如果有什么我可以帮忙的,请随时告诉我。
推荐阅读
- r - 使用函数内部的 dyplr 将字符串转换为数据屏蔽
- php - 在 Laravel 中启用 MARS
- nvidia - 无人机版本未获得 M300 OSDK
- blockchain - 现有的区块链系统如何处理多方交易?
- python - 如何在 Pygame 中使图像重复 - 例如连续 10 次
- sql - Spark SQL 场景没有给出正确的结果
- javascript - JS设置值时useState钩子不更新
- python - 使用ajax调用将参数发送到python脚本
- github - 我在我的 github 文件中删除了 2 个文件,但没有提交。但是当我写 git status 时,它说已删除
- c# - VS 2019、.NET 5.0.402、C# 中的数据断点(VS 2022、.NET 6.0 相同)