首页 新闻 赞助 找找看

c# wcf如何接收 text , text/plain ,text/xml的参数

0
悬赏园豆:10 [已解决问题] 解决于 2019-08-02 17:11

如题 在c#中,如何接收 text , text/plain ,text/xml 这几个类型的参数,需要怎么配置

目前我的wcf服务端代码如下:

   [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest,  UriTemplate = "CallbackInvoice?AuthData={AuthData}")] 
    
        [OperationContract]
        string CallbackInvoice (string AuthData,string req);

但是只能接收 application/json的数据格式 不支持其他的

龙益阳的主页 龙益阳 | 初学一级 | 园豆:140
提问于:2019-07-31 18:49
< >
分享
最佳答案
0

参考 WCF WebInvoke which can accept content-type: text/plain?

namespace StackOverflow36216464
{
    public class RawContentTypeMapper : WebContentTypeMapper
    {
        public override WebContentFormat GetMessageFormatForContentType(string contentType)
        {
            switch (contentType.ToLowerInvariant())
            {
                case "text/plain":
                case "application/json":
                    return WebContentFormat.Json;
                case "application/xml":
                    return WebContentFormat.Xml;
                default:
                    return WebContentFormat.Default;
            }
        }
    }
}
收获园豆:10
dudu | 高人七级 |园豆:31075 | 2019-08-01 08:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册