ASMX不扔SOAP错误 [英] ASMX not throwing SOAP faults
问题描述
我的ASP.NET 3.5 Web服务(ASMX)不抛出异常作为SOAP错误。我所看到的一切说,这是默认的行为,但该矿发送所有异常信息为文本/平原。这是一个新的Web应用程序项目添加了一个服务。从开箱行为没有其他变化。我如何获得SOAP错误?
code:
[WebService的空间(namespace =http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)
[System.ComponentModel.ToolboxItem(假)]
公共类的WebService:System.Web.Services.WebService
{
[的WebMethod]
公共字符串的HelloWorld()
{
INT TEST1 = 0;
INT测试2 = 5 / test1的; 返回的Hello World;
}
}
结果:
HTTP / 1.1 500内部服务器错误
服务器:ASP.NET开发服务器/ 10.0.0.0
日期:星期二,2011 GMT 21时39分23秒10月25日
的X ASPNET-版本:2.0.50727
缓存控制:私人
内容类型:text / plain的;字符集= UTF-8
内容长度:201
连接:关闭System.DivideByZeroException:试图除以零。
在WebApplication.WebService.HelloWorld()在C:\\ .... CS:23行
ASMX Web服务将只与SOAP响应,如果请求是SOAP。该服务为您生成的测试页不包括SOAP请求信封:
POST HTTP://server/service.asmx/HelloWorld HTTP / 1.1
接受:* / *
内容类型:应用程序/ x-WWW的形式urlen codeD
内容长度:0
主持人:服务器
一个适当的SOAP请求是这样的:
POST HTTP://server/service.asmx HTTP / 1.1
内容类型:文本/ xml的;字符集= UTF-8
SOAPAction报:HTTP://服务器/的HelloWorld
主持人:服务器
内容长度:283
期望:100-继续< XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封
的xmlns:SOAP =http://schemas.xmlsoap.org/soap/envelope/
XMLNS:XSI =http://www.w3.org/2001/XMLSchema-instance
的xmlns:XSD =http://www.w3.org/2001/XMLSchema>
<肥皂:身体与GT;
<的HelloWorld的xmlns =HTTP://服务器//>
< / SOAP:身体与GT;
< / SOAP:信封>
注意SOAPAction头字段和SOAP信封的内容。如果该请求是有效的SOAP请求的服务将与SOAP响应作出响应。对于初始例如,下面的SOAP错误是响应
HTTP / 1.1 500内部服务器错误
日期:星期六,2011 GMT 16时55分17秒11月5日
内容类型:文本/ xml的;字符集= UTF-8
内容长度:695< XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封
的xmlns:SOAP =http://schemas.xmlsoap.org/soap/envelope/
XMLNS:XSI =http://www.w3.org/2001/XMLSchema-instance
的xmlns:XSD =http://www.w3.org/2001/XMLSchema>
<肥皂:身体与GT;
<肥皂:故障>
<故障code>肥皂:服务器16; /故障code>
< faultstring>
System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---&放大器; GT; System.DivideByZeroException:试图除以零。
在Service.HelloWorld()在C:\\测试\\ Service.asmx.cs:行35
---内部异常堆栈跟踪的结尾---
< / faultstring>
<细节/>
< / SOAP:故障>
< / SOAP:身体与GT;
< / SOAP:信封>
My ASP.NET 3.5 web service (asmx) is not throwing exceptions as SOAP faults. Everything I've seen says this is the default behavior but mine is sending all exception information as text/plain. This is a new web application project with one service added. No other changes from out of the box behavior. How do I get SOAP faults?
Code:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
int test1 = 0;
int test2 = 5 / test1;
return "Hello World";
}
}
Result:
HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/10.0.0.0
Date: Tue, 25 Oct 2011 21:39:23 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 201
Connection: Close
System.DivideByZeroException: Attempted to divide by zero.
at WebApplication.WebService.HelloWorld() in C:\....cs:line 23
ASMX web services will only respond with SOAP if the request was SOAP. The testing page generated for you by the service doesn't include the SOAP request envelope:
POST http://server/service.asmx/HelloWorld HTTP/1.1
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
Host: server
A proper SOAP request looks like this:
POST http://server/service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://server/HelloWorld"
Host: server
Content-Length: 283
Expect: 100-continue
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<HelloWorld xmlns="http://server/" />
</soap:Body>
</soap:Envelope>
Notice the SOAPAction header field and the SOAP envelope content. If the request is a valid SOAP request the service will respond with a SOAP response. For the initial example, the following SOAP fault is the response:
HTTP/1.1 500 Internal Server Error
Date: Sat, 05 Nov 2011 16:55:17 GMT
Content-Type: text/xml; charset=utf-8
Content-Length: 695
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>
System.Web.Services.Protocols.SoapException: Server was unable to process request. --- > System.DivideByZeroException: Attempted to divide by zero.
at Service.HelloWorld() in C:\Test\Service.asmx.cs:line 35
--- End of inner exception stack trace ---
</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
这篇关于ASMX不扔SOAP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!