Well now, just when I think I'm done with this little project they throw me another curve...
I have two WCFs. One hosted in IIS and the other is in a self-hosted service on a different server.
A function in the self-hosted service returns a PDF in the form of Byte(). The WCF in IIS calls the function, then uses System.IO.FileStream to write the PDF to intepub. The aspx performs a callback, and the page is reloaded with a dynamic iFrame displaying the pdf. Works good enough for me, but not good enough for the boss.
Somehow, I have to get the second WCF to pass the PDF back to my ASP app WITHOUT saving it to disk.
I need something like:
iFrameControl.Attributes.Add("src", ServiceReference1.GetPDF_Byte())
Any way to do this?
Thanks in advance,
Jason
If I understand you correctly, there is some action in the ASPX page which causes a call (possibly passing some parameter) to be made to the first service (WCF1, hosted in IIS), which in turn calls the second service (WCF2, from a different machine); WCF1 retrieves the PDF from WCF2, saves it locally in inetpub and returns the URL of the saved file; the callback call on the ASPX page then uses that URL to display the PDF on the iFrame.
A short answer: you can't use a service reference to do what you need (ServiceReference1.GetPDF_Byte()) - the "src" attribute for the control (or for any XML) needs to be a string, which in this case represents the URL of the resource which is the actual source for the control. You can, however, use WCF to implement that - a REST endpoint in the "raw" mode (http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx) can be used to return a PDF file.
You would change the structure of your application as follows: some action in the ASPX page causes it not to make a call to WCF1 directly, but to simply set the "src" property of the iFrame control to a call to a REST endpoint in WCF1. This call would take the parameters, and call WCF2 to retrieve the PDF file, and that call would return the PDF file directly (as a Stream). This way you don't incur the buffering cost that you would in your buffer solution (if many clients are requesting the page at the same time you may have some memory issues, and in this case you don't need to manage buffer lifetimes either).
Found it somewhere else in C and did a conversion, posting here just in case someone else needs it.
Answer: Create a new class (Globals.vb) to house a byte array that can be accessed from both pages, then create a new page and do a response.BinaryWrite your byte array in Page Load, and set the iFrame's src to the new (blank) page.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.BinaryWrite(Globals.PDF_Data.ToArray)
End Sub
Related
I am working on generating a report in episerver in the form of a scheduled job.This report is basically used to get all the contents(page types,blocks,media) within Episerver.
There are some good nuget packages for content usages but for some reason& to have more control & plans for tweeking & extending it further,i am creating a custom one rather than using the available 3rd party packages.
The scheduled job is kind of similar to
https://www.codeart.dk/blog/2018/12/content-report-generator/ .
The article helped me a lot to get my report working with some modifications as per my requirement.
The one thing that I am struggling here is to get the URL of where the block is. Now this is a point of debate here.
I am aware that the blocks being shared in nature can be used anywhere in a site but the point is they are still used in pages or as a matter of fact in other blocks which is turn is used on a page.What i am trying to say here is,they directly or indirectly are part of a page.So is there a way to get the page url of a block irrespective of how many pages they are in.
Every forum I have looked at ,there's always page url of Pagedata or mediadata & nothing on blockdata.Even 3rd party nuget packages that i have looked for does not have page url for block types.
I do understand that there is nothing out of the box here.Is there a way to achieve this ie get the page url of a specific block type which can be a list of page urls if the block is used in multiple pages.
Recursive function to reach the page:
private string GetPublicUrl(IContentRepository contentRepository, IContentSoftLinkRepository contentSoftLinkRepository, ContentReference contentReference)
{
var publicUrl = string.Empty;
var content = contentRepository.Get<IContent>(contentReference);
var referencingContentLinks = contentSoftLinkRepository.Load(content.ContentLink, true)
.Where(link => link.SoftLinkType == ReferenceType.PageLinkReference && !ContentReference.IsNullOrEmpty(link.OwnerContentLink))
.Select(link => link.OwnerContentLink);
foreach (var referencingContentLink in referencingContentLinks)
{
publicUrl = UrlResolver.Current.GetUrl(referencingContentLink.GetPublicUrl()) ?? GetPublicUrl(contentRepository, contentSoftLinkRepository, referencingContentLink);
}
return publicUrl;
}
I have written this recursive function to reach the page ,but this works only when there is a single level. For instance A 2Col block on a page.
If I have a block say Download Block which is on a 2Col block which in turn is on a page ,then in this case the url is empty.
Any input is appreciated.
With IContentSoftLinkRepository you can find where the blocks are used. You can check whether the SoftLink points to a page with SoftLink.SoftLinkType == PageLinkReference and then use IUrlResolver to get the page's URL.
I access a 3rd party website using forms authentication (username and password).
Once logged on I make a call to a HTTP endpoint and receive XML in the body. The XML contains 1000 XML elements. Within each element there is a text value, a code.
For each of these codes I make a further call to a different HTTP endpoint. The response is more XML.
When all 1000 responses have been received I would like to add all the XML responses as files to a zip container and make it available for download.
I would like to see how LogicApps could do this as quickly as possible.
Make the call to the first HTTP endpoint (auth set to basic auth with user/pass inputted)
Use the xpath(xml(<body var here>), '//elementNameHere') expression on the Body of the result from the call to get all the elements of the return value that have the code in it
Foreach over this return value and
make the HTTP call
append the result to an array variable, or concat on to a string variable.
Submit this value to blob storage
Because you're messing w/ vars in the foreach loop, though, you'll have to do it sequentially (set concurrency control on the Foreach Loop to 'on' and '1') else you could end up with a bad result.
I don't know of a way to "zip contents" here so you may have to send the result to an Azure Function that uses a .Net zip lib to do the work (or js zip lib, whatever your flavor) and does the put to blob storage for you.
This would also all be much easier in Durable Functions land, I encourage you to look in to that if you're so inclined.
One mild alternative you might consider is for step 3.2, instead upload that result to a blob storage container, then make the entire container available for download via an Azure Function call which gets the container & zips up the contents (or does the Blob Storage URL for a container do this for you already? not sure)
I've run into some difficult-to-refactor classic ASP code. It's saving data from Request.Form into the database. It's doing so by using:
Dim RequestData
RequestData = Request.BinaryRead(Request.TotalBytes)
Before this happens, I'd like to remove a particular field from Request.Form, however the documentation on BinaryRead indicates that if you touch Request.Form before or after BinaryRead, you'll get an error.
I could potentially change this on the pages requesting this functionality, but that would be extremely complicated.
So, I was thinking of doing something like this:
Dim tempData
tempData = Request
tempData.Form("BadField") = ""
requestBytes = ConvertToSafeArray(tempData) 'I'm not aware of anything that actually does this
So, any thoughts?
You can check Pure ASP Upload or ASP Uploader. Since ASP can't handle files in a normal upload, these libraries parse form fields and files out of the binary request data into an internal data structure.
You could modify them to ignore or erase special fields.
Im trying to use Microsoft.Office.Interop.Word._Document.Close() in a .net 3.5 windows form app.
No matter how much I search here and on Google I cannot find the correct parameters to put in the Close method.
I am using version 14.0.0.0 of Microsoft.Office.Interop.Word and I would like to close the document without saving and ideally ensure that the application can isolate the document thread so that users can still open word documents outside the running application.
See the Close method of the Document class described in MSDN. If you need to omit the parameter and use the default value - pass the Type.Missing parameter.
Try this:
object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object missing = System.Reflection.Missing.Value;
_Document.Close(ref doNotSaveChanges, ref missing, ref missing);
This is the source
I'm not sure if you'll need the middle line or not. It's not from the original source it's from here
I am trying to make WatiN attach to an IE popup window (IE 10).
This popup contains a frameset --> a single frame --> a pdf document.
My goal is to save this pdf to my disk.
Dim winExists = IE.Exists(Of IE)(Find.ByUrl(Function(url) url.Contains("__ADFvDlg")))
If winExists Then 'this evaluates to true
Dim win = IE.AttachTo(Of IE)(Find.ByUrl(Function(url) url.Contains("__ADFvDlg"))) ' Timeout while waiting for frame document becoming available
End If
1) I have tried using the above code inline or in a STA thread
2) When coded inline, its parent thread is also STA
3) I have tried to increase the default timeout to 8 minutes, same result after 8 minutes have passed
There is no other option for me than to parse this particular popup, since it is a site built with Oracle ADF and, apart from the fact that it is A MESS, it is very strange at times...this popup has a URL that somehow works only once. If I try to use it in another window, no pdf is returned. The same happens when I refresh the popup.
I cannot fetch the PDF in the Temporary Internet Files since it is not there (I suppose this is because the website works under SSL).
Any guidelines or solutions even outside WatiN's scope is more than welcome since I've hit a brick wall.
Technologies: VS2012, WPF
Thanks a lot in advance.
I found it easiest when I tried the same thing by making the pop-up show up as a new tab. That way I could attach to it's URL. From there I would use
File.WriteAllText(fileName, responseDownLoad.Content.ReadAsStringAsync().Result);
Where responseDownload will be a HttpResponseMessage