public class SendIdocSample { internal class MyBodyWriter : BodyWriter, IDisposable { #region Constructors /// /// Initializes a new instance of the BodyWriter class. /// /// The message contents. public MyBodyWriter(Stream stream) : base(false) { if (stream == null) throw new ArgumentNullException("stream"); this.stream = stream; } #endregion Constructors #region IDisposable Members /// /// Disposes of the underlying stream. /// public void Dispose() { if (this.stream != null) { this.stream.Dispose(); } } #endregion #region Fields /// /// Protected. The message contents. /// protected Stream stream; #endregion Fields #region Methods /// /// Protected sealed override. Writes out the contents of the message body. /// /// The XmlDictionaryWriter used to write out the message body. protected sealed override void OnWriteBodyContents(XmlDictionaryWriter writer) { XmlReaderSettings settings = new XmlReaderSettings(); settings.CheckCharacters = false; settings.CloseInput = false; using (XmlReader reader = XmlReader.Create(this.stream, settings)) { reader.MoveToContent(); writer.WriteNode(reader, false); } } #endregion Methods } public static void Main() { SAPBinding binding = new SAPBinding(); binding.SendTimeout = new TimeSpan(0, 5, 0); binding.AcceptCredentialsInUri = true; EndpointAddress outboundaddress = new EndpointAddress( "sap://Client=800;lang=EN;User=Developer1;passwd=password@A/ADAPSAP47/00"); IChannelFactory channelFactory = (IChannelFactory)binding.BuildChannelFactory(); channelFactory.Open(); IOutputChannel outputChannel = channelFactory.CreateChannel(outboundaddress); outputChannel.Open(); //MATMAS05.txt contains the idoc data in "flat-file" format, //wrapped within the //i.e., within the "" //and "" tags. using (FileStream inputFileStream = new FileStream("MATMAS05.txt", FileMode.Open, FileAccess.Read)) { using (MyBodyWriter bodyWriter = new MyBodyWriter(inputFileStream)) { using (Message inputMessage = Message.CreateMessage(MessageVersion.Default, "http://Microsoft.LobServices.Sap/2007/03/Idoc/SendIdoc", //Action bodyWriter)) { outputChannel.Send(inputMessage); } } } outputChannel.Close(); channelFactory.Close(); } }