Receive large texts via AIF
19. December 2012 Leave a comment
One of our customer’s business partner transmits data as XML file. However, they did not make it to use a structured xml document service, but send a string that (in most cases) contains a valid xml document. Therefore we’ve setup an AIF service, using a class that takes one str parameter called _txt and stores it at a memo field.
public void storeText(str _text)
{
AifBigData bigData;
;
bigData.Text = _text;
bigData.insert();
}
However, the business partner recently told us they get an error message while transmitting data to the AIF service telling them the transmitted data is too large. We were able to reproduce the issues by calling the service using a larger random-generated text.
class Program
{
static void Main(string[] args)
{
var client = new BigData.BigDataServiceClient();
client.ClientCredentials.Windows.ClientCredential = new
System.Net.NetworkCredential("user","pass123","domain");// works fine
client.storeText("Hello World");// fails 😦
string txt = GenerateBigText();
client.storeText(txt);
}private static string GenerateBigText()
{
var random = new Random();
var sb = new StringBuilder();
for (int i = 0; i < 61440; i++)
{
char c = (char)random.Next(65, 122);
sb.Append(c);
}return sb.ToString();
}
}
The second call results in an exception
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://insideax.at/bigdata:_text. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.
However, the exception is well explained and contains a solution proposal to set the MaxStringContentLength
Go to Basic > AIF > Services > Button Configure
Select Binding > basicHTTPBinding > ReaderQuotas > MaxStringContentLenght and set e.g. 2147483647
Save and generate the .NET artifacts. Open windows explorer and navigate to the AIF virtual directory e.g. C:\Program Files\Microsoft Dynamics AX\50\AifWebServices . Select the web.config and open it with internet explorer. Make sure the MaxStringContentLength value is set
With this configuration the service call will work and a large text message is stored properly in Dynamics AX