【发布时间】:2016-07-15 17:00:24
【问题描述】:
我有一个 C# ASMX Web 服务(旧项目,无能为力)。它必须接收的请求之一带有动态 HTTP 标头“TransactionID”,并且必须在响应中的 HTTP 标头中返回。
当返回成功消息对象时,这工作正常,但是当返回 SOAPFault 消息时,所有自定义 HTTP 标头都被清除,我找不到恢复它们的方法。客户端坚持必须发送失败消息。我试过使用 SOAPExtension,但它没有 HTTP 标头的可见性。我试过放置
HttpContext.Current.Response.AddHeader("TransactionID", TransactionId);
在一系列不同的地方,无济于事。
代码如下:
[WebMethod(MessageName = "name")]
[SoapHeader("Header")]
[SoapMessageLoggingExtension]
[SoapDocumentMethod("http://www.contoso.com/DocumentLiteral", RequestElementName = "requestName", ResponseElementName = "responseName")]
[return: System.Xml.Serialization.XmlElementAttribute("ReturnType")]
public ResponseType WebMethodName(object RequestObject)
{
bool success = true;
int errorType = 0;
string errorMsg = String.Empty;
string TransactionId = String.Empty;
SoapException soapEx = null;
try
{
TransactionId = HttpContext.Current.Request.Headers["TransactionID"].ToString();
//Determine success or throw appropriate exception
}
catch //example exception
{
success = false;
ErrorType = 1;
errorMsg = "ErrorText";
soapEx = new SoapException(_errorType.ToString() + " : " + errorMsg, SoapException.ServerFaultCode);
}
finally
{
HttpContext.Current.Response.AddHeader("TransactionID", TransactionId);
if (success)
{
resp = new SuccessResponse();
}
}
if (soapEx != null) throw soapEx;
return resp;
}
我不知所措...这是预期的行为吗?如果是这样,有什么办法可以解决吗?还是我只是太密集了?
如果我遗漏了任何重要信息,请告诉我,谢谢。
【问题讨论】:
标签: c# web-services soap asmx