2
votes

I'm receiving this error in a Message Assignment shape within my orchestration. Within this assignment shape, I'm trying to execute an XPath query to extract a base64 encoded string from a message received by WCF. I'm then trying to load an XmlDocument variable with a Stream generated by a helper class that I've written. The base64 string will be the contents of either a PDF or Excel file (note: this is not XML). I've read that this can be done.

Here is the expression used in my Message Assignment:

messageCreator = new IAS.Integration.Services.Helpers.MessageCreator();
System.Diagnostics.EventLog.WriteEntry("IAS.Integration.Services.Orchestration", "MessageCreator Object created");

base64 = xpath(PerformTransformationResponse, "string(/*[local-name()='PerformTransformationResponseWrapper' and namespace-uri()='http://www.iasreo.com/integration/servicetypes']/*[local-name()='TransformedPayload'])");
//System.Diagnostics.EventLog.WriteEntry("IAS.Integration.Services.Orchestration", System.String.Format("Base64 from xpath: {0}", base64));

Output = new System.Xml.XmlDocument();
System.Diagnostics.EventLog.WriteEntry("IAS.Integration.Services.Orchestration", "Output instantiated as XmlDocument");

messageCreator.CreateMyMessage(Output, base64);
System.Diagnostics.EventLog.WriteEntry("IAS.Integration.Services.Orchestration", "messageCreator.CreateMyMessage(Output, base64)");

Here are the helper classes I've written to support this expression:

[Serializable]
public class MessageCreator
{
    public void CreateMyMessage(XLANGMessage outMessage, string binaryStringMessage)
    {
        outMessage[0].LoadFrom(new StreamFactory(binaryStringMessage));
    }
}

[Serializable]
public class StreamFactory : IStreamFactory
{
    private string messageContent;

    public StreamFactory(string inMessageContent)
    {
        messageContent = inMessageContent;
    }

    public Stream CreateStream()
    {
        byte[] messageBytes = Convert.FromBase64String(messageContent);

        return new MemoryStream(messageBytes, 0, messageBytes.Length, true, true);
    }
}

Finally, this is the error I receive in the Event Viewer:

xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'IAS.Integration.Services.Orchestrations.MainOrchestration(fcad6d68-ce54-bfa2-d035-56608b99ef52)'. The service instance will remain suspended until administratively resumed or terminated. If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception. InstanceId: c398fd2a-b654-4981-be13-94146d640375 Shape name: Send_StreamedDocument ShapeId: bc7a463b-eed2-4222-b2f7-3fdb1e44a3c5 Exception thrown from: segment 1, progress 25 Inner exception: The part 'part' of message 'Output' contains zero bytes of data.

Exception type: EmptyPartException Source: Microsoft.XLANGs.Engine Target Site: System.IO.Stream Persist(System.String ByRef, Boolean) The following is a stack trace that identifies the location where the exception occured at Microsoft.XLANGs.Core.Part.Persist(String& encoding, Boolean wantEncoding) at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.StagePartData(Part part) at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.PrepareMessage(XLANGMessage msg, IList promoteProps, IList toPromote) at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.WriteMessageState(IBTPEPInfoLookup pepLookup, Guid portId, XLANGMessage msg, Segment seg, String opname, String url, IList promoteProps, Boolean track, IList toPromote) at Microsoft.BizTalk.XLANGs.BTXEngine.BTXLogicalPortBinding.SendMessage(XLANGMessage msg, XlangStore store, Segment seg, OperationInfo op, IList additionalProps, IList toPromote, Boolean ignoreRoutingFailure) at Microsoft.BizTalk.XLANGs.BTXEngine.BTXPortBase.SendMessage(Int32 iOperation, XLANGMessage msg, Correlation[] initCorrelations, Correlation[] followCorrelations, Context cxt, Segment seg, ActivityFlags flags) at IAS.Integration.Services.Orchestrations.MainOrchestration.segment1(StopConditions stopOn) at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)**

1

1 Answers

1
votes

I can see it is happening when you are serializing the message as part of persisting state just before sending it. "Shape name: Send_StreamedDocument"

Is your OutPut message defined as a simple message or a multipart message?

Have you tried making the OutPut message a string instead of XMLDocument?

Edit: Actually the XMLDocument is not itself serializable. I didn't know that - I guess I have always managed to type my messages to something schema based before sending them out.
See here: http://talentedmonkeys.wordpress.com/2010/02/15/xmldocument-serialization-in-biztalk-2009-not/ And here: http://extremelytalentedmonkeys.blogspot.com/2009/12/xmldocument-serialization-not.html

You could wrap your message assignment and send shape in an atomic transaction so you avoid trying to persist something that is not serializable. Or you could use something else than an XMLDocument?