- 0
[C#] Am I missing a pitfall with base64 encode sending?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Microsoft has delayed Outlook REST API deprecation indefinitely due to customer feedback
By Usama Jawad96,
- 0 replies
- 3 views
-
KB5012643 is causing issues with some apps in Windows 11, but there's a workaround
By Usama Jawad96,
- microsoft
- windows 11
- (and 12 more)
- 3 replies
- 15 views
-
- 12 answers
- 11863 views
-
- 2 answers
- 2428 views
-
- 2 answers
- 2203 views
-
Question
sathenzar
I am always learning different parts of the C# language b/c lets face it, it's a lot of fun :). I've decided to configure my wcf service as a rest service which supports json request/response instead of xml. All has gone well and I can serialize/deserialize my messages into complex classes so far, unless I send a bunch of data in them. I've tried to change my readerQuotas, etc, etc but everytime I try to make a call it says "Error: Bad Data". I know the service works because I can call simple functions and pass data to/from the service. But if I pass a class with 3 byte[] properties each 128 bytes in length it fails. If I pass the same class with each byte[] param with 3 bytes of data it goes through (I base64 encode each complex class after serializing them). Here is my example code:
This example passes and goes through:
GetTestSalesRequest req = new GetTestSalesRequest() { CurrentTest = new byte[] { 1 }, CurrentMTest = new byte[] { 4 }, UserName = this.gl_userName,// <---- is a string UserPwd = new byte[] { 2 } }; string test = await this.gl_client2.TestFunc(req); System.Diagnostics.Debug.WriteLine("Test function: {0}", test);This example fails.
GetTestSalesRequest req = new GetTestSalesRequest() { CurrentTest = CryptographicEngine.Encrypt(keySvr, Encoding.UTF8.GetBytes(test1.ToString()).AsBuffer(), null).ToArray(), // <---- is a byte[] CurrentMTest = CryptographicEngine.Encrypt(keySvr, Encoding.UTF8.GetBytes(test2.ToString()).AsBuffer(), null).ToArray(), //<---- is a byte[] UserName = this.gl_userName,// <---- is a string UserPwd = this.gl_userPwd // <--- is a byte[] }; string test = await this.gl_client2.TestFunc(req); System.Diagnostics.Debug.WriteLine("Test function: {0}", test);public async Task<string> TestFunc(GetTestSalesRequest request) { string resBody = null; byte[] testStr = Encoding.UTF8.GetBytes(WebHelperClass.SerializeJSONObj<GetTestSalesRequest>(request)); string addr = string.Format("{0}/TestFunc/{1}", this.gl_baseAddr, Convert.ToBase64String(testStr)); WebRequest req = WebRequest.Create(addr); HttpWebResponse res = await req.GetResponseAsync() as HttpWebResponse; if (res.StatusCode == HttpStatusCode.OK) { using (Stream stream = res.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { resBody = sr.ReadToEnd(); sr.Dispose(); } } } return resBody; }Is there a pitfall I'm going into here? What am I missing that is really obvious because this has to be possible to be done.
Link to comment
https://www.neowin.net/forum/topic/1126840-c-am-i-missing-a-pitfall-with-base64-encode-sending/Share on other sites
10 answers to this question
Recommended Posts