Skip to content

Instantly share code, notes, and snippets.

@yaronn
Created July 31, 2014 18:17
Show Gist options
  • Save yaronn/39e53ef30ff060656dd5 to your computer and use it in GitHub Desktop.
Save yaronn/39e53ef30ff060656dd5 to your computer and use it in GitHub Desktop.
pass information from encoder to proxy
http://wcfswaencoder.codeplex.com/
http://www.codeplex.com/Download?ProjectName=wcfswaencoder&DownloadId=87250
http://wcfswaencoder.codeplex.com/SourceControl/latest
public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeaders, string contentType)
{
VerifyOperationContext();
if (contentType.ToLower().StartsWith("multipart/related"))
{
byte[] ContentBytes = new byte[stream.Length];
stream.Read(ContentBytes, 0, ContentBytes.Length);
MimeContent Content = _MimeParser.DeserializeMimeContent(contentType, ContentBytes);
if (Content.Parts.Count >= 2)
{
MemoryStream ms = new MemoryStream(Content.Parts[0].Content);
Message Msg = ReadMessage(ms, int.MaxValue, Content.Parts[0].ContentType);
Msg.Properties.Add(SwaEncoderConstants.AttachmentProperty, Content.Parts[1].Content);
return Msg;
}
else
{
throw new ApplicationException("Invalid mime message sent! Soap with attachments makes sense, only, with at least 2 mime message content parts!");
}
}
else if (contentType.ToLower().StartsWith("text/xml"))
{
XmlReader Reader = XmlReader.Create(stream);
return Message.CreateMessage(Reader, maxSizeOfHeaders, MessageVersion);
}
else
{
throw new ApplicationException(
string.Format(
"Invalid content type for reading message: {0}! Supported content types are multipart/related and text/xml!",
contentType));
}
}
private static void TestUzeDownload(string DialogId)
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Downloading UZE with attachment...");
Console.WriteLine("-----------------------------------");
Console.WriteLine();
AbsCompleteTest.GinaUze2.UzeServiceClient Client =
new AbsCompleteTest.GinaUze2.UzeServiceClient("SwaUzeEndPoint");
using (OperationContextScope Scope = new OperationContextScope(Client.InnerChannel))
{
AbsCompleteTest.GinaUze2.RetrieveUzeAnlageReq Request = new AbsCompleteTest.GinaUze2.RetrieveUzeAnlageReq()
{
svNummer = ConfigurationManager.AppSettings["All_SVNummer"],
uzeCode = ConfigurationManager.AppSettings["Uze_UzeCode"],
uzeId = int.Parse(ConfigurationManager.AppSettings["Uze_UzeId"]),
version = int.Parse(ConfigurationManager.AppSettings["Uze_UzeVersion"])
};
Client.retrieveUzeAnlage(DialogId, Request);
if (OperationContext.Current.IncomingMessageProperties.ContainsKey(SwaEncoderConstants.AttachmentProperty))
{
Console.WriteLine("Attachment Property received!!");
byte[] b = (byte[])OperationContext.Current.IncomingMessageProperties[SwaEncoderConstants.AttachmentProperty];
using (FileStream fs = new FileStream(ConfigurationManager.AppSettings["All_ZipFilePathSave"], FileMode.Create))
{
fs.Write(b, 0, b.Length);
fs.Flush();
}
Console.WriteLine("Written to file {0}!",
ConfigurationManager.AppSettings["All_ZipFilePathSave"]);
}
}
Console.WriteLine("Done!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment