C# 来自asmx web服务的故障消息格式
strong文本 我有一个基本web服务(asmx),它抛出soap异常。下面是service.asmx和web.config的代码。我期待web服务在IE中以下面的格式回复。但我在IE中以一行“这是例外”得到回复。你能帮我获得下面给出的格式吗。我无法理解在哪里更改?在任何web.config文件或asmxC# 来自asmx web服务的故障消息格式,c#,C#,strong文本 我有一个基本web服务(asmx),它抛出soap异常。下面是service.asmx和web.config的代码。我期待web服务在IE中以下面的格式回复。但我在IE中以一行“这是例外”得到回复。你能帮我获得下面给出的格式吗。我无法理解在哪里更改?在任何web.config文件或asmx service.aspx ============ <%@ WebService Language="C#" Class="zzz" %> using System.Web
service.aspx
============
<%@ WebService Language="C#" Class="zzz" %>
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
[WebServiceBinding()]
public class zzz : WebService
{
[WebMethod()]
public void abc()
{
throw new SoapException("this is the exception", SoapException.ClientFaultCode);
}
}
expecting the response as below
===============================
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Validation Exception</faultstring>
<detail>
<ErrorCode>TESTCODE</ErrorCode>
<ErrorDescription>No matching emp information. Please change your request.</ErrorDescription>
</detail>
</soap:Fault>
service.aspx
============
使用System.Web.Services;
使用System.Web.Services.Protocols;
使用System.Xml;
[WebServiceBinding()]
公共类zzz:WebService
{
[WebMethod()]
公共图书馆
{
抛出新的SoapException(“这是异常”,SoapException.ClientFaultCode);
}
}
希望得到如下回复
===============================
soap:客户端
验证例外
测试代码
没有匹配的emp信息。请更改您的请求。
web.xml
===============================
我认为问题可能出在IE设置中,特别是“显示友好的http错误消息”选项
请与Fiddler一起检查原始http输出。附上您在IE中看到的内容,我在IE中看到下面的消息。它只有一行“这是例外”。但是我需要我的问题的格式,答案在这里,托马斯,我在IE中得到下面的信息。它只有一行“这是例外”。但是我需要问题中的格式托马斯,我启用了“显示友好的http错误消息”,但是我在屏幕上看到了以下错误。“网站无法显示页面”HTTP 500。我不知道;我不知道如何附加屏幕截图。
web.xml
===============================
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<customErrors mode="On"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>