【问题标题】:How to pass multiple parameters in WCF Rest Service: string and Stream in C#如何在 WCF Rest Service 中传递多个参数:C# 中的字符串和流
【发布时间】:2020-05-02 01:58:46
【问题描述】:

我有一个 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# rest wcf stream


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 2015-04-10
    • 1970-01-01
    • 2014-09-17
    • 2010-10-17
    • 2013-02-11
    • 1970-01-01
    • 2021-03-22
    相关资源
    最近更新 更多