2012-07-10 37 views
0

strong text 我有一個基本的web服務(asmx)拋出了soap異常。以下是service.asmx和web.config的代碼。我期待在IE中以下格式的Web服務響應。但我在IE中獲得了單行的響應,因爲「這是例外」。請你幫我獲取下面給出的格式。我無法理解在哪裏更改?在任何web.config文件或asmx中?來自asmx 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> 

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> 
+0

附上你在IE中看到的請 – 2012-07-10 21:51:08

+0

托馬斯,我在IE下面得到消息。它唯一的一行「這是例外」。但我需要在我的問題的格式 – user1515989 2012-07-11 01:41:22

+0

答案在這裏https://msdn.microsoft.com/en-us/en-en/library/aa480514.aspx – fubo 2015-01-30 09:47:18

回答

0

我覺得這個問題可以在IE的設置,特別是 「顯示友好HTTP錯誤信息」 選項。

使用Fiddler檢查原始http輸出。

+0

托馬斯,我在IE下面得到消息。它唯一的一行「這是例外」。但我需要格式在我的問題 – user1515989 2012-07-11 01:39:29

+0

托馬斯,我啓用「顯示友好的HTTP錯誤消息」,但我在屏幕上獲得以下錯誤。 「網站無法顯示頁面」HTTP 500.我不知道如何連接屏幕截圖。 – user1515989 2012-07-11 01:49:52