How to upload files larger than 16k to a WCF-service? - asp.net-mvc

To make a long story short:
Making a web application
Each user profile contains exactly one profile image, which is stored in the database
The bottom layer uses ADO.NET entity framework for data access and relationships between classes
Inserting images into the database on the bottom data access layer of the application works fine
On the top layer, in an MVC application, we use WCF to get the profile image to display. Displaying the image works fine no matter what the size, meaning that uploading images is the only problem.
In my Upload picture-function i can upload pictures up to 16k. Nothing bigger.
I have found all maxBufferSize and maxReceivedMessageSize properties in all app.config and web.config-files in the solution, and changed the values to 1MB (1 048 576)
This is the error i get:
The formatter threw an exception while
trying to deserialize the message:
There was an error while trying to
deserialize parameter
http://www.mydomain.com/contracts/profile/2009/07:userProfile.
The InnerException message was 'There
was an error deserializing the object
of type
Myproject.Commons.BusinessObjects.UserProfile.
The maximum array length quota (16384)
has been exceeded while reading XML
data. This quota may be increased by
changing the MaxArrayLength property
on the XmlDictionaryReaderQuotas
object used when creating the XML
reader. Line 1, position 44978.'.
Please see InnerException for more
details.
It also tells me that the source file of the error is Reference.cs within the service reference.
...and now i basically cannot understand where this really comes from. Anyone has a clue?

The error message says it all, really :-)
The maximum array length quota (16384)
has been exceeded while reading XML
data.
Besides all the maxBufferSize etc. settings, there's also a set of settings called ReaderQuotas which you can set when customizing a binding. One of those settings if the "maxArrayLength" which defaults to 16'384.
<bindings>
<wsHttpBinding>
<binding name="Default" bypassProxyOnLocal="true"
useDefaultWebProxy="true" >
<readerQuotas maxArrayLength="16384"
maxBytesPerRead="4096"
maxDepth="32"
maxNameTableCharCount="16384"
maxStringContentLength="8192"/>
</binding>>
</wsHttpBinding>
</bindings>
These settings influence how the DataContractSerializer on the server will deserialize your message - you can look up details on the MSDN docs and set the values as you need them.
Marc

Related

Turning on Saxon performance analysis in eXist-db

I've used the performance analysis tool in Saxon (https://www.saxonica.com/documentation11/index.html#!using-xsl/performanceanalysis) to analyze stylesheets, and it's quite useful. I'd like to do the analysis from within eXist-db rather than the command line. For one, the performance could be different. But mainly because some stylesheets open documents in exist-db, and I can't run these from the command line. Is there a way to configure Saxon to output the profile.html document when it's run via eXist-db?
I was hoping there would be an attribute in conf.xml , or attributes that could be sent via transform:transform(), but I don't see any options related to the performance analysis tool.
I can't be certain this will work, but it's worth a try.
The $attributes parameter of Exist-db's transform() method allows you to set Saxon configuration properties. The available properties are listed at https://www.saxonica.com/documentation11/index.html#!configuration/config-features . You could try setting the properties TRACE_LISTENER_CLASS (to "net.sf.saxon.trace.TimingTraceListener") and TRACE_LISTENER_OUTPUT_FILE (to the required "profile.html" output file).
Incidentally, note that the performance is going to be different when you run with a trace listener. The profile generated using -TP is useful because it tells you which templates and functions are accounting for the most time and therefore need attention; the absolute numbers are not important or accurate. The hot spots will almost certainly be the same whether you are running within eXist or from the command line.
I can confirm this did work. Here's the XQL I used:
let $params :=
<parameters>
</parameters>
let $attributes :=
<attributes>
<attr name="http://saxon.sf.net/feature/traceListenerClass" value="net.sf.saxon.trace.TimingTraceListener"/>
<attr name="http://saxon.sf.net/feature/traceListenerOutputFile" value="/tmp/profile.html"/>
</attributes>
let $serialization := 'method=html5 media-type=text/html indent=no'
return transform:transform($xml, $xsl, $params, $attributes, $serialization)

F# SqlProvider - how to access stored procedure results?

I am using SQLProvider from NuGet (https://www.nuget.org/packages/SQLProvider/ v1.1.42) in an F# project to access our MSSQL database.
I am referring to the sample code from here, https://fsprojects.github.io/SQLProvider/core/programmability.html and also the source code tests on GitHub, https://github.com/fsprojects/SQLProvider/blob/master/tests/SqlProvider.Tests/scripts/MySqlTests.fsx.
#r #"....\packages\SQLProvider.1.1.42\lib\net451\FSharp.Data.SqlProvider.dll"
#r #"....\System.Data.Linq.dll"
open System
open FSharp.Data.Sql
open FSharp.Data.Sql.Common
open System.Data.Linq
type SeriesResult = { .. fields .. }
[<Literal>]
let ConnectionString = #"connStr"
type Sql = SqlDataProvider<
ConnectionString = ConnectionString,
DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER>
let db = Sql.GetDataContext()
let test =
[
for f in db.Procedures.MyStoredProcedure.Invoke("param").ResultSet do
yield f.MapTo<SeriesResult>()
]
I need to access results from the call to MyStoredProcedure, but ResultSet errors with error FS0039: The field, constructor or member 'ResultSet' is not defined". I also get this for ColumnValues, and on MapTo (presumably because the type is unknown).
Is there an additional library I should be referencing?
I have: FSharp.Core, FSharp.Data, FSharp.Data.SqlProvider, mscorelib, System, System.Core, System.Data, System.Data.Linq, System.Xml.Linq
Thanks!
(wanted to tag with SQLProvider - but can't!)
One possible reason for this is that the intelli-sense thread probably timed out waiting for a response from the SQL provider.
The stored procs and the set of types to carry the result ResultSet are computed lazily (when you type the .). This is good in one way as it means the provider doesn't introspect the entire database on instantiation, pulling in lots of stuff you're probably not going to use. However it does have the side effect, of needing to do a non-trivial amount of work in the . completion on the first request, we cache the result after that. I believe Microsoft have a metric that says any intelli-sense work should complete in 250ms, but what the actual thread timeout is I'm not sure. With a language like C# and F# hitting a response target of 250ms can be a big ask on large solutions, but throw a database in the mix (even a small local database) this becomes a very hard target to hit.
Quite why it didn't recover and try again until you added the references, will only be known to Visual Studio; Usually however just closing and re-opening the file is enough. In rare cases unload the project from the solution and reload.

How to set a timeout in VoiceXML?

In VoiceXML, how can I set the timeout when start the xml?
This is my VoiceXML document:
<vxml version="2.1">
<form>
<block>
<prompt>Hello from VXML</prompt>
</block>
<transfer name="result" dest="tel:+12321312" bridge="true">
<prompt>Please wait while we transfer you.</prompt>
<grammar xml:lang="en-US" root = "TOPLEVEL" mode="voice">
<rule id="TOPLEVEL" scope="public">
<one-of>
<item> disconnect </item>
</one-of>
</rule>
</grammar>
</transfer>
</form>
</vxml>
Two transfer property you can use:
connecttimeout The time to wait while trying to connect the call before returning the noanswer condition. The value is a Time Designation . Only applies if bridge is true. Default is platform specific.
maxtime The time that the call is allowed to last, or 0s if no limit is imposed. The value is a Time Designation . Only applies if bridge is true. Default is 0s.
I'm not completely sure what you mean. If you want to set up a timeout so that it throws an error if that vxml page you posted is not fetched within that time, you can set the fetchtimeout property before your first form.
If you go to the W3C, it says:
A VoiceXML interpreter context needs to fetch VoiceXML documents, and other resources, such as audio files, grammars, scripts, and objects. Each fetch of the content associated with a URI is governed by the following attributes:
fetchtimeout
The interval to wait for the content to be returned before throwing an error.badfetch event. The value is a Time Designation (see Section 6.5). If not specified, a value derived from the innermost fetchtimeout property is used.
fetchhint
Defines when the interpreter context should retrieve content from the server. prefetch indicates a file may be downloaded when the page is loaded, whereas safe indicates a file that should only be downloaded when actually needed. If not specified, a value derived from the innermost relevant fetchhint property is used.
maxage
maxscale

Where can I get adwords report response xml fixture/mock

Hi fellow stackoverflowers! :)
I am wiring my application with adwords API, and want it to display reports based on the retrieved data. My problem is that I am using test account that have no data that could be used for reporting, and so far us I understand testing account don`t provide any. According to the https://developers.google.com/adwords/api/docs/test-accounts#developing_with_test_accounts I should fake data. I am totally fine writing tests and feed then with fixtures, expect I can't find any relevant example of how the response XML will look like so I can create my own fixtures.
For example:
I want to pull campaign performance report, and segment it by Week
<reportDefinition>
<selector>
<fields>CampaignId</fields>
<fields>Clicks</fields>
<fields>Impressions</fields>
<fields>Week</fields>
<predicates>
<field>CampaignId</field>
<operator>EQUALS</operator>
<values>111111</values>
</predicates>
<dateRange>
<min>20150201</min>
<max>20150601</max>
</dateRange>
</selector>
<reportName>Campaign Performance Report NAme</reportName>
<reportType>CAMPAIGN_PERFORMANCE_REPORT</reportType>
<dateRangeType>CUSTOM_DATE</dateRangeType>
<downloadFormat>XML</downloadFormat>
<includeZeroImpressions>true</includeZeroImpressions>
</reportDefinition>
Which gives me response:
<report>
<report-name name="Campaign Performance Report NAme" />
<date-range date="Feb 1, 2015-Jun 1, 2015" />
<table>
<columns>
<column name="campaignID" display="Campaign ID" />
<column name="clicks" display="Clicks" />
<column name="impressions" display="Impressions" />
<column name="week" display="Week" />
</columns>
</table>
What will be the response with actual data? How it is going to look like in case segmentation will be set to: Date, Month, Quarter, Year?
I have tried to find any xml example on the web and github without luck. Can you please share response examples or point me to the doc, where it says how can I "generate" data for my test acount?
Thank you!
eolexe, I am assuming you did not receive an error for the Campaign Performance Report you tried to fetch. If that is the case then that means there was no match for the predicates and date range you had entered. This why you do not have the rows element within the XML. Also some attributes are are not filterable. But I am pretty sure the CampaignID is. Take a close look at the API just to be sure. You need to migrate to version 201502 because 201402 is deprecated and 201409's sunset day is in July.
I have been working on AdWords API for reporting purpose for years, and I can tell you up till now there is still no official sample XML or CSV given. So I simply test the program using real account data...
I don't pick XML as the response type so I cannot really address your question, but you may wish to know that the XML response does not return a total row. That's why I always pick CSV/TSV format.

The field 'Commons' not defined in freebase provider for fsharp

I'm having some problems with the freebase api. I have managed to put a key to the freebase provider so I don't see any 403 errors, relating quota restrictions. But since I used a google api key, commons is not being recognized when I hit "alt + enter". But while I'm writing, the provider manages to show me data.
[<Literal>]
let FreebaseApiKey = "AIzaSyCOn15-T31Ls"
type FreebaseDataWithKey = FreebaseDataProvider<Key=FreebaseApiKey>
let dataWithKey = FreebaseDataWithKey.GetDataContext()
let travelDestinations = dataWithKey.Commons.Travel.``Travel destinations``
let all = travelDestinations |> Seq.toList
let first = all.Head.Name
As you can see, I have access to Travel Destinations, so the provider shows me data correctly but when I execute it:
Script.fsx(17,38): error FS0039: The field, constructor or member 'Commons' is not defined
The weird thing is that if I delete the google key, and use the provider, this error does not happen. Any clues?
In a provider like freebase, we need to do things asynchronously, and that unfortunately causes the error reporting not to be very good (see https://github.com/fsharp/fsharp/issues/280)
What's probably happening is that freebase is returning errors due to the api key not being right or something similar, and does errors are not surfacing, as the toplevel objects are already cached. You can either look under Fiddler to see the json being returned, use data.DataContext.SendingQuery or data.DataContext.SendingRequest, or clean the cache by deleting the FreebaseSchema and FreebaseRuntime folders under your temporary internet files system folder.
We recently tried to change this to cause errors to surface by generating the toplevel types synchronously, but that caused other problems (https://github.com/fsharp/FSharp.Data/issues/522)

Resources