我有一个BizTalk 2009编排,其中包含Request-Response端口类型,该端口类型被发布为WCF Basic-HTTP Web服务。该端口有一个操作,该操作具有适当的模式的请求和响应消息。在此端口收到请求后,在某些情况下,应将故障消息返回客户端而不是标准响应消息。我很难将正确的故障消息回到客户端。我想能够设置 faultcodefaultstring SOAP故障消息的元素。这是我尝试的:

添加类型字符串的故障消息:我尝试在操作中添加带有消息类型的字符串类型的故障消息。在编排中,我构建了一个字符串消息,并将其作为响应发送。交付给客户的错误看起来像:

<?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">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;string>This is the error message.&lt;/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>&lt;?xml version="1.0" encoding="utf-8"?>
&lt;string>This is the error message.&lt;/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我以为我可能会说服BizTalk沿着我期望的构造的内容返回错误消息 Fault 元素并发送。因此,我添加了一个类型的故障消息 http://schemas.xmlsoap.org/soap/envelope/#Fault, ,构建适当的消息并将其作为响应发送。结果与上述相同,除非而不是字符串 faultstring 元素包含一个 CDATA 部分带有我内部构建的整个XML消息。

所以我现在被困了;我觉得这应该是BizTalk中的一项简单任务。 MSDN上的文档, 如何抛出以WCF服务出版的编排的错误例外, ,告诉您有关“如何”抛出故障例外的任何内容,除了可以抛出它们,您需要设置 includeExceptionDetailInFaults 在配置中(我已经完成了)。

有人对Biztalk 2009如何实现这一目标有任何建议吗?

有帮助吗?

解决方案

我通过添加自定义WCF IDISPATCHMESSAGEINSPECTOR解决了这个确切的问题,在其中我从序列化消息中读取原因文本,然后返回一个新的System.ServiceModel.faultException Message Message Message Message Message Message Message Message Message。

在BizTalk编排中,我使用System.String作为PortType故障消息类型。

public class HandleUntypedSoapFault : IDispatchMessageInspector
{

    public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {

        if (reply.IsFault)
        {

            MessageBuffer buffer = reply.CreateBufferedCopy(int.MaxValue);
            MessageFault messageFault = MessageFault.CreateFault(buffer.CreateMessage(), int.MaxValue);

            if (!messageFault.HasDetail)
            {
                reply = buffer.CreateMessage();
                return;
            }

            using (XmlReader reader = XmlReader.Create(new StringReader(messageFault.Reason.ToString())))
            {
               reader.MoveToContent();
               string _faultText =  reader.ReadElementContentAsString();
            }

            reply = Message.CreateMessage(
                reply.Version, 
                new FaultException(
                    _faultText, 
                    new FaultCode("client")).CreateMessageFault(),
                null);
        }
    }
}

现在,肥皂剧看起来更像是这样:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <s:Fault>
         <faultcode>s:Client</faultcode>
         <faultstring xml:lang="en-US">An untyped SoapFault from my BizTalk orchestration. This text was set in the orchestration.</faultstring>
      </s:Fault>
   </s:Body>
</s:Envelope>

其他提示

让我想起了我前一段时间参加的这个漫长的话题:http://social.msdn.microsoft.com/forums/en-us/biztalkr2adapters/thread/f69ec7af-a490-490-4229-4229-81d4-3d4-3d1b41b41b41b41bf9c48/

他们指的是可能对您有帮助的SDK示例,但这是一个键入(不按您要求的)故障例外。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top