如何将裸结果返回到WCF客户端

如何将裸结果返回到WCF客户端,wcf,wcf-rest,Wcf,Wcf Rest,我有如下代码: <OperationContract()> <Description("")> <WebGet(Bodystyle:=WebMessageBodyStyle.Bare, UriTemplate:="TestConnection")> Function TestConnection() As String Public Function TestConnection() As String Implements ITestSvc.TestCo

我有如下代码:

<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

函数TestConnection()作为字符串
公共函数TestConnection()作为字符串实现ITestSvc.TestConnection
WebOperationContext.Current.OutgoingResponse.ContentType=“text/plain”
返回“连接成功”
端函数
但它返回的是
连接成功

没有XML包装器,我怎么能只返回“连接成功”。我知道我们可以用MessageEncoder做点什么。但是,我希望它在操作级别可用(某些操作需要XML/JSON包装,而某些操作不需要)


有人能帮我吗?

答案在这里(对我来说很有用)

这里是返回纯文本的最简单解决方案。将响应格式设置为xml,并将outgoingresponse设置为text/html。我们应该做到这一点

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

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

如果你在处理HTTP,有一种方法可以实现这一点,它并不太好,但我想我可以提一下

您可以将方法的返回类型设置为void,然后直接将原始字符串输出到响应中

[OperationContract]
[WebGet(UriTemplate = "foo")]
void Foo()
{
   HttpContext.Current.Response.Write("bar");
}

这很好,它帮助了我,而其他人没有,谢谢对我不起作用