- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图让 WebFaultException 以 json 和 xml 的形式返回,这取决于客户端的要求,如
中所述我的服务界面是这样的
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "session_record?id={id}&command={command}")]
void SessionRecord(Guid id, String command);
异常
throw new WebFaultException<string>("Session not started", HttpStatusCode.Conflict);
Web.config 服务设置
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" faultExceptionEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
我的客户调用该服务
$.ajax({
url: "Webservice/session_record?id={id}&command={command}".format({ id: $("#sessionGuid").val(), command : "start" }),
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert("Started");
}
});
除了从服务器接收 json,我得到的是 xml
当我在我发布的链接中阅读它时,我应该可以
With the WebFaultException, the detail of the exception that is serialized in the body of >the response message will always be in the format (XML or JSON) that the client would have >received had there not been an error. If the client was expecting XML, the client will >get the exception detail serialized as XML. Likewise, if the client was expecting JSON, >the client will get the exception detail serialized as JSON.
最佳答案
我找到了解决方案; faultExceptionEnabled 需要为 false。现在我得到了 json 中的异常。
关于c# - WCF WebHttp 服务中的错误处理,仅带有 WebFaultException xml 格式的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8167202/
我正在使用 WCF Webhttp 服务。我创建了一堆服务,剩下的就是放入用户身份验证... 问题 与其余架构风格保持一致,我是否应该针对用户 db 验证每个服务调用。 如果是这样,我应该在每次调用服
我目前有一个带有 webHttp 绑定(bind)的 WCF 服务,我试图通过覆盖配置中的默认设置来增加可以输入服务的最大大小,我尝试过类似的操作
所有这些都与 WebHttp 绑定(bind)有关,托管在自定义服务主机中(IIS 目前不是一个选项)。 我已经实现了自定义 UserNamePasswordValidator 和自定义 IAutho
我正在开发一个将数据从安卓手机传输到服务器的解决方案(用 C#/.NET 编写)。 我创建了一个 WCF 服务并用模拟器测试一切正常。然后当我尝试从手机(连接到家庭 wifi 网络)登录时,我收到以下
在配置 WCF-WebHttp 安全选项卡时,我已将安全模式设置为 Transport,将客户端凭据类型设置为 Certificate。 当我浏览客户端证书时,出现的唯一选项是 Current Use
场景: 我想调用 RESTish 服务 我想用WCF webHttpBinding调用服务 该服务接受 GET 请求,例如: GET /endpoint/{resourcename}/?arg1=a&
我有一个简单的基于 REST 的服务,我正在尝试使用 ChannelFactory 为其创建客户端代理。我想没有配置文件,所以我尝试在代码中执行此操作,并且我相信我拥有 .config 中除行为之外的
我在 Windows 服务中托管了一个 WCF 服务。我已经向它添加了一个具有 webHttp 行为的 webHttpBinding,每当我向它发送 GET 请求时,我都会得到 http 200,这正
我正在创建一个带有 wsHttp 和 JSON 端点的网络服务。下面的配置托管在网站项目中并且工作正常,除非我尝试在网站内创建服务引用。端点行为似乎导致错误: "Extension Error 'we
我试图让 WebFaultException 以 json 和 xml 的形式返回,这取决于客户端的要求,如 中所述 http://blogs.msdn.com/b/endpoint/archive/
WCF-BasicHttp、基于 WCF-WebHttp 适配器的接收和发送端口的安全选项卡中的客户端证书和服务证书 Prop 有什么区别,BizTalk 如何使用它们进行 SSL 身份验证?文档不是
WCF 中的 webHttp 和 enableWebScript 有什么区别?我应该将哪个用于 WCF REST POST 请求? 最佳答案 要使您的 WCF 服务成为 RESTful,您必须使用 W
我有一个桌面 webapi 服务器,我想通过 azure 服务总线的中继 WebHttpRelayBinding 向客户端公开,是否有一种简单的方法可以捕获来自服务总线的所有消息并将它们作为 http
我正在使用 RESTful 方法构建 Web 服务,并使用 WCF WebHttp API (.NET v4)。为了满足一些遗留功能,我需要通过 POST 接受原始 XML 消息并对其进行处理。例如,
基本上我想创建一个 https 安全的 Restful WCF 服务。因此,我正在为我的服务使用 webhttpbinding,因为它支持创建 RESTful 服务。最好我想用单个实例 EBS 来做,
我目前正在满足为大型映射请求提供路由的需求,该请求最多可以包含 30 个查询字符串项。 在开发我的 BizTalk 项目时,我已经成功地使用 WCF-WebHttp 类型接受带有少量查询字符串的 ht
我们希望通过 REST 和 TCP 公开我们的 WCF 服务,并使用 SSL 保护它们。我们已将有效的 SSL 上传到 Azure 并进行正确的映射设置,以便转到 https://service.ou
我是一名优秀的程序员,十分优秀!