简体   繁体   English

如何在 WCF Rest Service 中传递多个参数:C# 中的字符串和流

[英]How to pass multiple parameters in WCF Rest Service: string and Stream in C#

I have a WCf rest service which has two input parameters : string and Stream:我有一个 WCf 休息服务,它有两个输入参数:字符串和流:

[OperationContract]      
[WebInvoke(Method = "POST", UriTemplate = "ImportStream/{Separator}", ResponseFormat = 
WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
void ImportStream(string Separator, stream data);

My code:我的代码:

public void ImportStream (string Separator, Stream inputpar)
{ //...
}

My objectif is to call the service with POSTMAN:https://localhost:44355/ServiceLias.svc/rest/ImportStream/Comma我的目标是使用 POSTMAN 调用服务:https://localhost:44355/ServiceLias.svc/rest/ImportStream/Comma

and in the body , I write the Stream as Text ,在正文中,我将 Stream 写为 Text ,

but I have error from the beginning :但我从一开始就有错误:

For request in operation ImportStream to be a stream the operation must have a single parameter whose type is Stream.

How can I fix it ?我该如何解决? Or there is any idea to achieve my objectif ?或者有什么想法可以实现我的目标吗? Thanks,谢谢,

The definition of the function signature doesn't comply with the rules to enable stream data in WCF.函数签名的定义不符合在 WCF 中启用流数据的规则。 It violates the below definition.它违反了以下定义。

The parameter that holds the data to be streamed must be the only parameter in the method.保存要流式传输的数据的参数必须是方法中的唯一参数。 For example, if the input message is the one to be streamed, the operation must have exactly one input parameter.例如,如果输入消息是要流式传输的消息,则操作必须正好有一个输入参数。 Similarly, if the output message is to be streamed, the operation must have either exactly one output parameter or a return value.类似地,如果要流式传输输出消息,则操作必须恰好有一个输出参数或返回值。

Please refer to the official document of how to enable Streaming.开启Streaming的方法请参考官方文档。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-enable-streaming https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-enable-streaming
Feel free to let me know if there is anything I can help with.如果有什么我可以帮忙的,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM