gpt4 book ai didi

wcf - 如何将裸结果返回给 WCF 客户端

转载 作者:行者123 更新时间:2023-12-04 13:42:38 29 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





WCF ResponseFormat For WebGet

(4 个回答)


7年前关闭。




我有如下代码:

<OperationContract()>
<Description("")>
<WebGet(Bodystyle:=WebMessageBodyStyle.Bare, UriTemplate:="TestConnection")>
Function TestConnection() As String


Public Function TestConnection() As String Implements ITestSvc.TestConnection
WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"
Return "Connection Success"
End Function

但它返回的是 <string xmlns='...'>Connection Success</string>
如何在没有 XML 包装器的情况下只返回“连接成功”。我知道我们可以用 MessageEncoder 做一些事情。但是,我想让它在操作级别可用(某些操作需要 XML/JSON 包装器,而某些操作不需要)。

谁可以帮我这个事?

最佳答案

这是返回纯文本的最简单的解决方案。将响应格式设置为 xml,将输出响应设置为 text/html。应该做的伎俩。

[WebGet(ResponseFormat = WebMessageFormat.Xml)]
public string DoWork()
{

WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
return "THIS IS PLAIN TEXT";
}

关于wcf - 如何将裸结果返回给 WCF 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3927520/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com