0

I'm trying to convert a base64 string to a pdf in my web service but for some reason it isn't working, my webserver returns a bad request. The last 4 lines are causing the issue.

I've followed a bunch of examples and gotten this far

Dim base64file As String = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB/lBMVEX///+VlZWZmZmRlpaTlpaTlZaSlZaTk5ORlZWTlZWTlZaSmJj///+TlpaTlZaTlZaUlJSAgICSlZWTlJaTlZaTlpaOjo6SlZeTlZaTlZaUlJaPj4+TlZWTlZaTlZeTlZeVlZWUlZaWlpaUlZWTlpaTlZaWlpaTlZeTlZaTlZaTlpaZmZmUlZaVlZWTlZaTlZeUlJiSlZaTlZaSlJaWlpaTlZaTlZaPmZmTlZaTlpaVlZWSlZaVlZWSkpKTlZaTlZWTlJaTlZaTlpaSkpKUlZaAgICLi4uTlJaTlZaTlpaAqqqUlJeTlZaTlZeVlZWUlpaTlZaUlZWUlJSfn5+UlpaSlpaTlZaUlZWRl5eQlpaTlZaSl5eUlZWZmZmTlZeTlZaTlZaUlpaUlJeTlZaSlpaTlZWUlZaTlZWTlZeSlZWTlZWTk5OUlpaTlpaTlJaSlJaOnJyJnZ2TlZWUlJiSlZeSkpKSlZWTlpaSlJeTlZaTlJaXl5eTlJaSlJaVlZWTlpaTlZaUlZaSkpiTlJaTk5iTlZeUlZWUlZeTlZWTk5mTlZWTlZaUlJaTlpaTlZaUlJSUlJSTlZaTlZaSlZeTlZaQkJuUlJSTlZaTlZaTlZWVlZWSlZeTlZaTlJaUlJeTlZWUlpaUlJSTlZaTlZeSlZWTlZWTlZWVlZWTlZYAAABfkBHsAAAAqHRSTlMAHQozrP3RGkG64ioBUMjvPgRe1fhVCWzg/nAQe+qQiRjyIpjc7i6m/OZoBdg8tHhFw/aIEfuXGdqnJLcwFc/GydNODt8CC73pbQZR8X0MX/eMEwiDRNmkLCe2Np0P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cKOaXKy5cYg2qUrl4j73qd3Yp2GmtnF3+drOzaVQmrOQPE8A0yT2726MQ9qfYyMdRNMlFuhMknowG5CemQGBtXxWXDcnC4TGXGx8hjm3xbigwQb90mW9F6J/XZehdiZMAHYnBXvnnvtJLF376lSMUGKE3QrbjnkxWTZBdHJ+Ww7x5d/MR0L6UxIFtxnxzegyQ+BHiEjwEe4yOAh5h8QA70fljTpTVAfEJLt3IEnkZlg+hTiD2jpf1Er2INupzMWT2nl5v3BcoG+ILeIIHnjCTO/ebrfsmEpVevI0lUDTAZef1KYgTJKUMxFjIviNHUjwrFAM1RJugeE7QCjHjeIA/VgMHbdy4Qo2LSltlAmmiA9HjflMlgIAAzwvTh40wGnz5DRuR+iaYz6P9amjmf4Nt3sYE/+z8dRY1Ggx81WacTBH/aWYPQr+Bs8gn6huKaQbyjZZbpFFNJ1aB2ag7pFGOJ3wC/E3/mmE7gIrfLoGvu+f8I/gKO8wApeMN4xQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNi0wMy0yOVQxODo0NzoyNCswMjowMCvzrPoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTYtMDMtMjlUMTg6NDc6MjQrMDI6MDBarhRGAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAABJRU5ErkJggg=="
            Dim bytes As Byte() = Convert.FromBase64String(base64file)

            Dim stream As New FileStream("c:\Users\me\Desktop\itworks.pdf", FileMode.CreateNew)
            stream.Write(bytes, 0, bytes.Length)
            stream.Close()
            opResult.success = True

What am I doing wrong?

AlexF11
  • 231
  • 1
  • 5
  • 20
  • 2
    `for some reason it isn't working` <= please be more specific. Do you have an exception? Is the file not on disk? You cant open the file? Your PC caught fire?... – Igor Sep 09 '16 at 15:21
  • @Igor edited, I can't really tell what's going on since it's on my webservice and just returns a bad request. If I comment out the last 3 lines the request is fine. – AlexF11 Sep 09 '16 at 15:23
  • Could be permissions related. Why can't you debug (attach the debugger to the running w3w instance?) ? – Igor Sep 09 '16 at 15:24
  • @Igor I can I'll just have to look up how. First webservice work I've done. – AlexF11 Sep 09 '16 at 15:25
  • [c# how to debug web service](https://www.google.com/search?q=c%23%20how%20to%20debug%20web%20service&rct=j) – Igor Sep 09 '16 at 15:27
  • 1
    You could check up the EventViewer on the server. I would also suggest you add logs. – the_lotus Sep 09 '16 at 15:35
  • @Igor no attach to process option in my version of visual studio thats on the server. Getting a new version then I'll attach the debugger – AlexF11 Sep 09 '16 at 15:45
  • Or as @the_lotus mentioned, add logging to your code and read the log. – Igor Sep 09 '16 at 15:48
  • @Igor not sure how to do that either – AlexF11 Sep 09 '16 at 15:49
  • @geostocker I'm not sure what I'm supposed to gather from that post – AlexF11 Sep 09 '16 at 15:53

1 Answers1

0

As the other guys mentioned you should add logs to your code to figure out the error.

This has some decent suggestions: Where does Console.WriteLine go in ASP.NET?

Otherwise you might be able to add a try-catch around the eroneous code and then print the exception to your log.

I'd assume that the log would show up in your browser much like a console.log would in JS.

If you run chrome simply get the developer tools up and find your console when yo uahve set up the code. That way you might get some more information surrounding the error.

This msdn URL has some information about try-catches: https://msdn.microsoft.com/en-us/library/f9shkfdd.aspx

But basically the idea is that you should be using something similar to:

Try
'Paste the code you are trying
Catch ex As Exception
'Add the log of your choice. In JS it would be Console.log(ex.message)
End Try
Community
  • 1
  • 1
geostocker
  • 1,190
  • 2
  • 17
  • 29
  • It was a permissions issue on the folder I was writing to. Solved that. Now I need to solve why the file won't open – AlexF11 Sep 09 '16 at 16:00
  • Cool. Hope my suggestion helped. If it did, then accept the answer and then post a new question with your new issue, if you can't solve it by yourself! Happy coding! :) – geostocker Sep 09 '16 at 16:01