首页 > 解决方案 > 如何在 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.

我该如何解决?或者有什么想法可以实现我的目标?谢谢,

标签: c#restwcfstream

解决方案


函数签名的定义不符合在 WCF 中启用流数据的规则。它违反了以下定义。

保存要流式传输的数据的参数必须是方法中的唯一参数。例如,如果输入消息是要流式传输的消息,则操作必须只有一个输入参数。类似地,如果要流式传输输出消息,则操作必须只有一个输出参数或返回值。

Streaming的开启方法请参考官方文档。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-enable-streaming
如果有什么我可以帮忙的,请随时告诉我。


推荐阅读