BizTalk Orchestration:响应非类型化 SOAP 错误
我有一个 BizTalk 2009 编排,其请求-响应端口类型已发布为 WCF Basic-HTTP Web 服务。该端口有一个操作,并且该操作具有具有适当架构的请求和响应消息。在此端口上收到请求后,在某些情况下,应向客户端返回错误消息而不是标准响应消息。我很难将正确的故障消息返回给客户端。我希望能够设置 SOAP 错误消息的 faultcode
和 faultstring
元素。这是我尝试过的:
添加字符串类型的故障消息: 我尝试向操作添加消息类型为字符串的错误消息。在编排中,我构建了一条字符串消息并将其作为响应发送。传送回客户端的错误看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
<faultstring xml:lang="en-US"><?xml version="1.0" encoding="utf-8"?>
<string>This is the error message.</string></faultstring>
<detail>
<ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HelpLink i:nil="true"/>
<InnerException i:nil="true"/>
<Message><?xml version="1.0" encoding="utf-8"?>
<string>This is the error message.</string></Message>
<StackTrace>at Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkAsyncResult.End() ...</StackTrace>
<Type>Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkNackException</Type>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
这几乎可以工作,除了 faultstring
元素包含我的字符串的 xml 序列化版本而不是字符串本身。我也无法设置 faultcode
元素。
添加类型为 http://schemas.xmlsoap.org/soap/envelope/#Fault
的故障消息 我想如果我构造 Fault
元素并发送它,我也许能够说服 BizTalk 返回一条与我期望的错误消息相同的错误消息。因此,我添加了一条类型为 http://schemas.xmlsoap.org/soap/envelope/#Fault
的错误消息,构造了适当的消息并将其作为响应发送。结果与上面相同,只是 faultstring
元素包含一个 CDATA
部分,而不是字符串,其中包含我在其中构造的整个 xml 消息。
所以我现在被困住了;我觉得这在 BizTalk 中应该是一个简单的任务。 MSDN 上的文档,如何从已发布的编排中引发故障异常作为 WCF 服务,没有告诉您“如何”抛出故障异常,除了可以抛出它们并且您需要在配置中设置 includeExceptionDetailInFaults
(我已经完成了) )。
有人对如何在 BizTalk 2009 中实现这一点有任何建议吗?
I have a BizTalk 2009 orchestration with a request-response port type that is published as a WCF Basic-HTTP web service. The port has one operation, and that operation has request and response messages with appropriate schemas. After receiving a request on this port, there are a few cases where a fault message should be returned to the client instead of the standard response message. I'm having difficulty getting the correct fault message back to the client. I'd like to be able to set both the faultcode
and faultstring
elements of the SOAP fault message. Here's what I've tried:
Adding a Fault Message of Type String:
I tried adding a fault message with a message type of string to the operation. Within the orchestration, I constructed a string message and sent it as the response. The fault that was delivered back to the client looked like:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
<faultstring xml:lang="en-US"><?xml version="1.0" encoding="utf-8"?>
<string>This is the error message.</string></faultstring>
<detail>
<ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HelpLink i:nil="true"/>
<InnerException i:nil="true"/>
<Message><?xml version="1.0" encoding="utf-8"?>
<string>This is the error message.</string></Message>
<StackTrace>at Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkAsyncResult.End() ...</StackTrace>
<Type>Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkNackException</Type>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
This almost works, except the faultstring
element contains the xml serialized version of my string instead of the string itself. I also cannot set the faultcode
element.
Adding a Fault Message of Type http://schemas.xmlsoap.org/soap/envelope/#Fault
I thought I might be able to convince BizTalk to return a fault message along the lines of what I'd expect if I constructed the Fault
element and sent that. So I added a fault message with a type of http://schemas.xmlsoap.org/soap/envelope/#Fault
, constructed the appropriate message and sent that as the response. The result was the same as above, except instead of a string, the faultstring
element contained a CDATA
section with the entire xml message I had constructed inside.
So I'm stuck now; I feel like this should be a simple task in BizTalk. The documentation on MSDN, How to Throw Fault Exceptions from Orchestrations Published as WCF Services, tells you nothing about "how" to throw fault exceptions, except that they can be thrown and that you need to set includeExceptionDetailInFaults
in the configuration (which I've already done).
Does anyone have any suggestions on how this could be accomplished in BizTalk 2009?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过添加自定义 WCF IDispatchMessageInspector 解决了这个问题,其中我从序列化消息中读取原因文本,然后使用反序列化原因文本返回新的 System.ServiceModel.FaultException 消息。
在 BizTalk 编排中,我使用 System.String 作为 PortType 故障消息类型。
现在 SoapFault 看起来更像这样:
I solved this exact problem by adding a custom WCF IDispatchMessageInspector where i read the reason text from the serialized message and then return a new System.ServiceModel.FaultException message using the deserialized reason text.
In the BizTalk orchestration i use System.String as the PortType fault message-type.
Now the SoapFault will look more like this:
想起我前段时间参加的这个长帖子:
http://social. msdn.microsoft.com/forums/en-US/biztalkr2adapters/thread/f69ec7af-a490-4229-81d4-3d1b41bf9c48/
它们引用了一个可能对您有帮助的 SDK 示例,但它是一个类型化的(不是非类型化的)按您的要求)故障异常。
Reminded of this long thread I participated in a while back:
http://social.msdn.microsoft.com/forums/en-US/biztalkr2adapters/thread/f69ec7af-a490-4229-81d4-3d1b41bf9c48/
They refer to an SDK sample that might help you, but it's a typed (not un-typed as you requested) fault exception.