The underlying connection was closed - webAPI ,WCF - c#

I have a REST Service calling a WCF service. The method in WCf service returns data as expected. Here is the Json format of the c#object.
[
{
"$id": "1",
"children": [],
"id": 1,
"name": "1",
"owner": {
"userId": 1,
"username": "testuser",
"firstName": null,
"lastName": null
},
"parent": null,
"permissions": [],
"type": 0
}
]
When There is a complex object the WCf service is throwing an error "The underlying connection was closed: The connection was closed unexpectedly"
[
{
"$id": "1",
"Children": [
{
"$id": "2",
"Children": [],
"Id": 603268262,
"Name": "testfolder",
"Owner": {
"UserId": 555,
"Username": "testuser",
"FirstName": null,
"LastName": null
},
"Parent": {
"$ref": "1"
},
"Permissions": null,
"Type": 0
}
],
"Id": 1,
"Name": "555",
"Owner": {
"UserId": 555,
"Username": "testuser",
"FirstName": null,
"LastName": null
},
"Parent": null,
"Permissions": null,
"Type": 0
}
]
I have tried most answers on this SO question. Why do I get the error only when a complex object is returned?

you need to check data contracts ,take a look at this : http://msdn.microsoft.com/en-us/library/aa347850.aspx

Found the answer just after posting the question. I did notice that there is a object holding a reference to a object in the Json
"Parent": {
"$ref": "1"
}
This is preventing the object from serialized. I did a deep copy and that fixed the issue

Related

How to check if any object in an array has a property in Azure Logic App

I am building a Azure Logic App which recieves vouchers array. I need to parse the body and stop execution if any voucher has the property canBeUsed to true. For achieving I want to use until instead of forEach because If I find any voucher with the property to true I want to stop iterating, I dont need to keep iterating.
In c# I would do this return response.Any(b => b.CanBeUsed);
The JSON received:
{
"vouchers": [
{
"amountPending": {
"currency": {
"code": "EUR",
"symbol": "€",
"id": 978
},
"amount": 1517
},
"amountPendingWithoutBonus": {
"currency": {
"code": "EUR",
"symbol": "€",
"id": 978
},
"amount": 1517
},
"canBeUsed": false,
"cannotBeUsedReasons": [],
"firstName": "jason",
"lastName": "denis",
"expirationDate": "2021-11-30T00:00:00",
"issuedDate": "2020-05-31T00:00:00",
"issuedReason": "Cancellation",
"voucherType": "Covid19",
"usages": []
},
{
"amountPending": {
"currency": {
"code": "EUR",
"symbol": "€",
"id": 123
},
"amount": 134
},
"amountPendingWithoutBonus": {
"currency": {
"code": "EUR",
"symbol": "€",
"id": 9718
},
"amount": 551
},
"canBeUsed": true,
"cannotBeUsedReasons": [],
"firstName": "paul",
"lastName": "frank",
"expirationDate": "2021-12-30T00:00:00",
"issuedDate": "2020-09-31T00:00:00",
"issuedReason": "Cancellation",
"voucherType": "Covid19",
"usages": []
}
]
}
What I have done:
I am stuck on accessing to the array inside the Until Customer Has Not Vouchers That Can Be Used.
I want to achieve this:
HasVouchersThatCanBeUsed = vouchers[i].canBeTrue;
You can use the Filter array action to filter the vouchers array by #item()?['canBeUsed'] equal to #true. Then you can check if the result array is empty.
You don't need the loop, unless you want to process the array items individually.

Does EntityFrameworkCore only retrieve to a certain depth in the nested objects?

I have a class called ConnectionsBank that has a list of Connections and a list of Connection Categories. The Connections class has a collection of PhoneNumber and ConnectionCategories. PhoneNumber class has a PhoneNumberType.
In my controller I have a Get that uses AutoMapper 7:
var result = await ControllerRepository.GetConnectionManagerAsync(connectionManagerdID);
return Ok(Mapper.Map<ConnectionManagerViewModel>(result));
The following is the return JSON:
{
"id": 1,
"jobSeekerID": 1,
"connections": [
{
"id": 1,
"completeName": {
"firstName": "Mary",
"lastName": "Jane"
},
"address": {
"street": "1 Main Street",
"city": "Rushville",
"state": "IN",
"country": "USA",
"zipCode": "99999"
},
"phoneNumbers": [
{
"phNumber": "317-922-8823",
"phoneType": null
}
],
"categories": null
}
],
"connectionCategories": [
{
"categoryName": "FIRST CONNECTION CATEGORY"
},
{
"categoryName": "SECOND CONNECTION CATEGORY"
}
]
}
Notice that "categories" and "phoneType" are null. The database has the data in the tables. Why would this happen? I am using EntityFrameworkCore 3.1.4.

How to get all values from JSON in c# 3.5 framework?

Below is my JSON response. I want to fetch orderid, caseid each filed one by one and their value.
"cases": [
{
"status": "DISMISSED",
"createdAt": "2015-09-18T08:56:04+0000",
"investigationId": 19246020,
"caseId": 19246020,
"score": 794.6295793608853,
"adjustedScore": 794.6295793608853,
"updatedAt": "2015-09-18T08:56:05+0000",
"headline": "Steven Rusk",
"orderId": "116588",
"orderDate": "",
"orderAmount": 425.0,
"associatedTeam": {
"teamName": "B2C Jewels",
"teamId": 4289
},
"reviewDisposition": null,
"uuid": "5821ed91-5f8f-4b51-bd63-a8834f2a95b3"
},
{
"status": "DISMISSED",
"createdAt": "2015-09-16T11:33:28+0000",
"investigationId": 19114061,
"caseId": 19114061,
"score": 241.65405995385285,
"adjustedScore": 241.65405995385285,
"updatedAt": "2015-09-18T19:07:51+0000",
"headline": "221.134.83.50",
"orderId": "101",
"orderDate": "2015-09-16T17:07:30+0000",
"orderAmount": 9.99,
"associatedTeam": {
"teamName": "B2C Jewels",
"teamId": 4289
},
"reviewDisposition": null,
"uuid": "301f2cfc-3b67-4fc0-bf83-19099c2ea4bf"
},
]
You will have to create a class named as cases and then you need to map your json to the List then you can iterate through the list hope it will work for you .
List<cases> = new JavaScriptSerializer().Deserialize<List<cases>>(your json string);
You can install Json.Net package from Nuget and then add this line of code in you project
var myList = Newtonsoft.Json.JsonConvert.DeserializeObject("Your Json String..!!");
this should do it

How to parse JSONData in C# (Windows Phone) using `this.`

In Windows Phone App.. I am parsing JSON Data By (get,set) method
I got another way of processing JSON data from this URL
In the part of this site (http://www.dfg-team.com/json-feeds-on-windows-phone/?lang=en)
Is used two techniques to parse json data..
in that I want to use this. Key word for processing JSON data ..
But My app have data Have a Lot of Json data which contains lot of JSON Arrays and JSON Objects. But its not a Problem in that I have main problem is My json contains Json array inside json object or json object inside the json array so at here we got problem.
This is My JSon data I want to parse these fields.. using this. method
{
"returnCode": "success",
"SData": {
"results": [
{
"wdetails": [
{
"noffers": [],
"offers_count": 0,
"name": "yahoo.com",
"recentoffers_count": 0,
"sku": "30072826",
"url": "http://www.yahoo.com"
},
{
"noffers": [
{
"id": "3aggEYoyaso",
"price": "179.99",
"firstrecorded_at": 13700,
"lastrecorded_at": 13700,
"seller": "google",
"availability": "In stock, ships same Business Day.",
"currency": "USD"
}
],
"offers_count": 1,
"name": "frys.com",
"recentoffers_count": 1,
"sku": "789",
"url": "http://www.google.com"
},
{
"listprice_currency": "USD",
"noffers": [
{
"id": "2SlCKQKm",
"price": "192.37",
"firstrecorded_at": 111,
"lastrecorded_at": 111,
"seller": "Amazon",
"availability": "13 In Stock",
"currency": "USD"
}
],
"offers_count": 1,
"name": "amazon.com",
"listprice": "288.56",
"recentoffers_count": 1,
"sku": "1084089",
"url": "http://www.amazon.com"
}
],
"model": "GGGG",
"weight": "771107.03",
"price_currency": "USD",
"gtins": [
"00839294"
],
"mpn": "GGGG",
"cat_id": "25552",
"height": "98.81",
"features": {
"Product Type - General": "Tablet",
"Height (in.)": "1.70"
},
"length": "416.56",
"geo": [
"usa"
],
"width": "267.97",
"category": "Tablets",
"price": "179.99",
"updated_at": 138,
"color": "Black",
"manufacturer": "google",
"images_total": 1,
"images": [
"https://evbdn.eventbrite.com/s3-s3/eventlogos/1832816/google.png"
],
"brand": "Dell",
"offers_total": 180
}
],
"total_results_count": 1,
"results_count": 1,
"code": "OK",
"offset": 0
}
}
I want to parse this Using this. in C#.
In Android I done this By hash map method, in Windows Phone this. is similar to is hash map so I am using this..
I am editing my previous answer :-
JObject json = JObject.Parse(yourJson);
if you need results to be parsed
this.ClassOfResult= json ["SData"]["results"];
if you want the 'wdetails' in the Json to get parsed you can try this
this.parentclass.wdetailsClass= json ["SData"]["results"]["wdetails"];
Hope that this will give you some idea.

How do i parse json? [duplicate]

This question already has answers here:
Parsing JSON using Json.net
(5 answers)
Closed 3 years ago.
I am using Newtonsoft Json library to parse json but i don't know how to use it. I parsed the string using JObject. When i output the value of JObject instance in immediate window i get this :-
json
{
"data": [
{
"id": "id",
"from": {
"name": "name",
"id": "someotherid"
},
"name": "pic",
"description": "desc",
"link": "linktosite",
"privacy": "everyone",
"count": 1,
"type": "normal",
"created_time": "2010-10-22T14:54:32+0000",
"updated_time": "2010-10-22T14:55:41+0000"
},
{
"id": "id2",
"from": {
"name": "name",
"id": "someotherid"
},
"name": "Profile Pictures",
"link": "link",
"privacy": "everyone",
"count": 6,
"type": "profile",
"created_time": "2010-10-12T14:27:58+0000",
"updated_time": "2011-01-01T18:38:14+0000"
},
{
"id": "id3",
"from": {
"name": "name",
"id": "829741958"
},
"name": "T",
"link": "link",
"privacy": "everyone",
"count": 5,
"type": "normal",
"created_time": "2010-05-01T03:03:39+0000",
"updated_time": "2010-05-01T03:19:13+0000",
"comments": {
"data": [
{
"id": "id",
"from": null,
"message": "message",
"created_time": "2010-08-28T18:27:10+0000",
"likes": 1
}
]
}
}
],
"paging": {
"previous": "paginglink",
"next": "otherpaginglink"
}
}
Count: 2
Type: Object
What should i do further to have the values from this jobject?
I personally prefer the JavaScriptSerializer for use with JSON in the .NET environment. By default it will return a Dictionary result, but can be used to parse in to a custom object (or you could make use of the dynamic datatype).
Some other posts on SO with JSON & JavaScript Serializer as topic

Categories