如何在客户端接受SOAPException
-
13-12-2019 - |
题
我得到了可怕的“客户端发现的响应内容类型的”text / html“但是预期的”test / xml“错误,但在一些googling我找到这篇文章关于如何返回soapexception。
所以我继续实施,但现在我仍然得到同样的错误。是否有更改需要在客户端上制作,以便能够接受SOAPException(我不会这么认为,一切刚从异常继承,右?)
为什么我仍然在客户端遇到可怕的响应?
[WebMethod]
[SoapHeader("authenticationHeader")]
[WebServiceAuthentication(AuthenticationRequired = false)]
public DataSet GetConversionErrors()
{
try
{
return Components.PWD.GetConversionErrors();
}
catch (Exception ex)
{
PublishingManager.Publish(ex, HttpContext.Current.User.Identity.Name);
throw Components.SoapException.GenerateSoapException(ex, Context);
}
}
.
编辑:我知道这个捕获块中的例外正是我需要看到的,但我仍然让system.invalidoperationException在客户端上。
edit2:我是通过Webreference(调用* .asmx文件)连接到WebServices,如果这有助于/最重要。
编辑3:这是写入我们的ExpereAllog服务器端(在PublishingManager.Publish()呼叫中)。我的思想是,这应该是返回客户的东西...
Exception Details:
Exception Type: System.Exception
Message: Test the text/html text/xml message.
Method: PWD.Components.PWD.GetConversionErrors
Username: xxxxxx Created 5/22/2012 4:20:53 PM
Application: xxxx Application Identity: NT AUTHORITY\IUSR
Source: xxxx Severity 2
Machine: xxxxxxxxx IP Address 127.0.0.1
AppDomain /LM/W3SVC/1/ROOT-1-129821937733610609
Stack Trace at PWD.Components.PWD.GetConversionErrors() in C:\Vault\Development-New\Web\Main_Logging\PWD\Components\PWD.cs:line 73
at PWD.PWD.GetConversionErrors() in C:\Vault\Development-New\Web\Main_Logging\PWD\PWD.asmx.cs:line 44
Additional Information:
+System.Exception:
Message: Test the text/html text/xml message.
Data: System.Collections.ListDictionaryInternal
InnerException:
TargetSite: System.Data.DataSet GetConversionErrors()
StackTrace: at PWD.Components.PWD.GetConversionErrors() in C:\Vault\Development-New\Web\Main_Logging\PWD\Components\PWD.cs:line 73
at PWD.PWD.GetConversionErrors() in C:\Vault\Development-New\Web\Main_Logging\PWD\PWD.asmx.cs:line 44
HelpLink:
Source: xxxx
UserName: xxxxxxx
TypeName: PublishingManager
MachineName: xxxxxxxxx
TimeStamp: 5/22/2012 4:20:54 PM
FullName: Services.Publishing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=null
AppDomainName: /LM/W3SVC/1/ROOT-1-129821937733610609
ThreadIdentity:
WindowsIdentity: NT AUTHORITY\IUSR
Severity: 2
MachineIPAddress: 127.0.0.1
.
编辑3:只想抛出这个额外的代码块,所以人们会看到我如何测试这些例外情况(也许这是测试的错误方法......)。在我的第一个代码块中,我在Try块内的呼叫到“return components.pwd.getconversionErrors();”,这是该方法:
public static DataSet GetConversionErrors()
{
DB db = new DB();
try
{
//return db.ExecuteDataset(Configuration.GenericConfig.AppConnectionString, CommandType.Text, spGetConversionErrors);
throw new Exception("Test the text/html text/xml message.");
}
catch
{
throw;
}
}
.
正如您所看到的,我已经评论了实际的呼叫,刚以我自己的行扔了一下,每次抛出一个例外,每次测试目的...
编辑4:@gbvb这是新方法:
[WebMethod]
[SoapHeader("authenticationHeader")]
[WebServiceAuthentication(AuthenticationRequired = false)]
public DataSet GetConversionErrors()
{
try
{
return Components.PWD.GetConversionErrors();
}
catch (Exception ex)
{
//PublishingManager.Publish(ex, HttpContext.Current.User.Identity.Name);
//throw Components.SoapException.GenerateSoapException(ex, Context);
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlNode detailNode = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, System.Web.Services.Protocols.SoapException.DetailElementName.Name, System.Web.Services.Protocols.SoapException.DetailElementName.Namespace);
detailNode.InnerText = ex.ToString();
throw new System.Web.Services.Protocols.SoapException(ex.Message, System.Web.Services.Protocols.SoapException.ClientFaultCode, System.Web.HttpContext.Current.Request.Url.AbsoluteUri, detailNode, ex.InnerException);
}
}
.
Edit5:什么FIDDLER2 SAW:
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 23 May 2012 19:25:56 GMT
Content-Length: 1208
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>500 - Internal server error.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>500 - Internal server error.</h2>
<h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
</fieldset></div>
</div>
</body>
</html>
.
如果有人知道恰好格式化本节,请执行以下操作:)
解决方案
所以,我搞定了。这是我发现的:
当在IIS中查看我的网站的属性时,然后选择“模块”,有一个名为“customErrormodule”的条目,它正在尝试处理网站/ Web服务抛出的错误。
修复程序要么删除该条目“customerRormodule”,或者更新我的配置文件:
<httpErrors errorMode="Custom" existingResponse="Replace">
.
到:
<httpErrors errorMode="Custom" existingResponse="Auto">
.
谢谢每个人的帮助,它朝着正确的方向转向我。(BTW,我正在更新配置文件,所以我不必用模块的东西混淆)
也,这是一个链接
其他提示
只是为了咯咯笑,你可以用SOAPException.ClientFaultCode显式抛出新的SOAPException()作为来自该呼叫的类型吗?显然,您有几个可能在上面显示的代码中失败的层,很容易搞砸(相信我,我知道:))。并不调用Publisher.publish等其他方法。这将指出它是否是消息声明(即ASMX基础架构),或者是您的代码搞乱了例外..