New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpProxy only supports XYZAsync calls? #4

Closed
ajj7060 opened this Issue Jun 17, 2015 · 9 comments

Comments

Projects
None yet
3 participants
@ajj7060

ajj7060 commented Jun 17, 2015

This is the same question from this forum post: http://forums.lhotka.net/forums/p/12856/58146.aspx

In investigating how to configure the HttpProxy, it looks like you can only use DataPortal.XYZAsync calls; the normal sync calls fail due to a condition enforced by the proxy.

What is the reason for this? We were hoping to move to this to support WP8.1 and other mobile platforms, but also for our WinForms client as well. The way it looks right now is that we'd either have to change all our factory methods to return Task and become async which also means code changes in our forms, or having to use WCF for the WinForms app and HttpProxy for everything else. Is there something else I'm missing?

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 17, 2015

Member

The reason is that System.Net.HttpClient only supports async calls over the network, while WCF supports sync and async network calls.

At the time I implemented HttpProxy my intent was to resolve the lack of WCF in WinRT by creating an alternate data portal channel, and trying to figure out how (or if) I could support sync calls over an inherently async network technology was out of scope.

Member

rockfordlhotka commented Jun 17, 2015

The reason is that System.Net.HttpClient only supports async calls over the network, while WCF supports sync and async network calls.

At the time I implemented HttpProxy my intent was to resolve the lack of WCF in WinRT by creating an alternate data portal channel, and trying to figure out how (or if) I could support sync calls over an inherently async network technology was out of scope.

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 17, 2015

Member

From a WinForms app perspective you might try calling something like FetchAsync and then waiting for the result:

var obj = DataPortal.FetchAsync<Customer>(123).Result;

If that doesn't cause a deadlock, it will provide your WinForms code with a synchronous result - blocking the UI just like it does today.

Member

rockfordlhotka commented Jun 17, 2015

From a WinForms app perspective you might try calling something like FetchAsync and then waiting for the result:

var obj = DataPortal.FetchAsync<Customer>(123).Result;

If that doesn't cause a deadlock, it will provide your WinForms code with a synchronous result - blocking the UI just like it does today.

@ajj7060

This comment has been minimized.

Show comment
Hide comment
@ajj7060

ajj7060 Jun 18, 2015

Thanks for explaining. We did try to use the .Result property in the factory method, but that was causing our sample app to hang completely. It didn't go to not responding though, but a deadlock would explain what we were seeing. What causes the deadlock?

If we can't figure this out I don't think it will be a big deal, it looks like I can host WCF in the same WebApi project hosting the HttpPortal.

ajj7060 commented Jun 18, 2015

Thanks for explaining. We did try to use the .Result property in the factory method, but that was causing our sample app to hang completely. It didn't go to not responding though, but a deadlock would explain what we were seeing. What causes the deadlock?

If we can't figure this out I don't think it will be a big deal, it looks like I can host WCF in the same WebApi project hosting the HttpPortal.

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 18, 2015

Member

I figured that's what would happen. I kind of think I tried using that to implement sync behavior in the proxy, but I don't remember for sure.

As I mentioned, WCF has sync methods, but they are just clever wrappers over async calls, because any network call is ultimately async at some level. The thing is, inside their implementation they are using some technique to not block the calling thread (typically the UI thread).

They might be spinning up a worker thread, but I bet they are using a lower level async IO callback technique from the OS (wrapped by WCF itself). Much, much more efficient than spinning a thread per call.

I think for my part in the HttpProxy my only option would be to use a worker thread. I can make that work, but I'm not sure what kind of cost we'd see, and I think the future is all async anyway, so I'm not entirely sure it is worth the effort.

Member

rockfordlhotka commented Jun 18, 2015

I figured that's what would happen. I kind of think I tried using that to implement sync behavior in the proxy, but I don't remember for sure.

As I mentioned, WCF has sync methods, but they are just clever wrappers over async calls, because any network call is ultimately async at some level. The thing is, inside their implementation they are using some technique to not block the calling thread (typically the UI thread).

They might be spinning up a worker thread, but I bet they are using a lower level async IO callback technique from the OS (wrapped by WCF itself). Much, much more efficient than spinning a thread per call.

I think for my part in the HttpProxy my only option would be to use a worker thread. I can make that work, but I'm not sure what kind of cost we'd see, and I think the future is all async anyway, so I'm not entirely sure it is worth the effort.

@ajj7060

This comment has been minimized.

Show comment
Hide comment
@ajj7060

ajj7060 Jun 18, 2015

Ya, I don't think any changes to Csla would be worth it. Our feeling is that we probably should move to async/await in WinForms as many of our calls do currently block the UI thread, but of course the issue is we can't do that as one big bang, we need to be able to convert over time.

I did manage to get a work around, at least in our POC solution:

public static SimpleReadOnlyBO GetSimpleReadOnlyBo() {
    Func<SimpleReadOnlyBO> func = () => GetSimpleReadOnlyBoAsync().ConfigureAwait(false).GetAwaiter().GetResult();
    return Task.Factory.StartNew(func).Result;
}

public static async Task<SimpleReadOnlyBO> GetSimpleReadOnlyBoAsync() {
    return await DataPortal.FetchAsync<SimpleReadOnlyBO>();
}

That seems to work, at least in our simple application. And I think we could also host a WCF data portal end point in the same WebApi project as the HttpPortal will be hosted, so I think we have some options here.

ajj7060 commented Jun 18, 2015

Ya, I don't think any changes to Csla would be worth it. Our feeling is that we probably should move to async/await in WinForms as many of our calls do currently block the UI thread, but of course the issue is we can't do that as one big bang, we need to be able to convert over time.

I did manage to get a work around, at least in our POC solution:

public static SimpleReadOnlyBO GetSimpleReadOnlyBo() {
    Func<SimpleReadOnlyBO> func = () => GetSimpleReadOnlyBoAsync().ConfigureAwait(false).GetAwaiter().GetResult();
    return Task.Factory.StartNew(func).Result;
}

public static async Task<SimpleReadOnlyBO> GetSimpleReadOnlyBoAsync() {
    return await DataPortal.FetchAsync<SimpleReadOnlyBO>();
}

That seems to work, at least in our simple application. And I think we could also host a WCF data portal end point in the same WebApi project as the HttpPortal will be hosted, so I think we have some options here.

@ajj7060 ajj7060 closed this Jun 18, 2015

@javed007

This comment has been minimized.

Show comment
Hide comment
@javed007

javed007 Aug 6, 2015

Visual Studio Code - Is this the new "Silverlight" combined with ASP.Net 5 ??

javed007 commented Aug 6, 2015

Visual Studio Code - Is this the new "Silverlight" combined with ASP.Net 5 ??

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Aug 6, 2015

Member

No, it is a lightweight code editor: https://code.visualstudio.com/

Member

rockfordlhotka commented Aug 6, 2015

No, it is a lightweight code editor: https://code.visualstudio.com/

@javed007

This comment has been minimized.

Show comment
Hide comment
@javed007

javed007 Aug 13, 2015

I am just about done converting my SL application to WPF, except for one very strange problem. In a large object graph, there is one final item that I have struggled with for over a week. The item is AllergyHx with a few simple fields and one collection called AllergySubstanceList.

In SL, as the object graph is being loaded from the parent down, AllergySubstanceList was set up just like all other fields of AllergyHx

In WPF, when I get to the line
set { SetProperty(allergyHxSubstanceListProperty, value); }
I get the error
Items collection must be empty before using ItemsSource.
After scratching my head for a few days, just on a whim, decided to change SetProperty to LoadProperty and lo and behold the error disappeared. But before I could do a happy dance, I realized that now when I clicked Save, I got an Edit Level Mismatch error.
I have tried:
[NotUndoable]
private AllergyHxSubstanceList _AllergyHxSubstanceList = allergyHxSubstanceListProperty.DefaultValue;
and on almost every other field in the object, but the only thing that helped the Mismatch Error was to change LoadProperty() to SetProperty() which meant not populate allergyHxSubstanceList. In SL, I never saw a Mismatch error on this object with the same exact fields at all.
Would appreciate any suggestion.
The complete error is:
An unhandled exception of type 'Csla.PropertyLoadException' occurred in Csla.dll
Additional information: Property load or set failed for property allergyHxSubstanceList (Items collection must be empty before using ItemsSource.)

PS: I rearranged my object graph and removed AllergyHxSubstanceList from AllegyHx. Everything is working fine now.
PS2: It has been said before, and I knew it and looked for it but just missed it. The AllergyHxSubstanceList is used in two different places in the UI. I checked and corrected one only. The listbox had a gratuitous . I removed it and all my troubles went away.

Javed

I am just about done converting my SL application to WPF, except for one very strange problem. In a large object graph, there is one final item that I have struggled with for over a week. The item is AllergyHx with a few simple fields and one collection called AllergySubstanceList.

In SL, as the object graph is being loaded from the parent down, AllergySubstanceList was set up just like all other fields of AllergyHx

In WPF, when I get to the line
set { SetProperty(allergyHxSubstanceListProperty, value); }
I get the error
Items collection must be empty before using ItemsSource.
After scratching my head for a few days, just on a whim, decided to change SetProperty to LoadProperty and lo and behold the error disappeared. But before I could do a happy dance, I realized that now when I clicked Save, I got an Edit Level Mismatch error.
I have tried:
[NotUndoable]
private AllergyHxSubstanceList _AllergyHxSubstanceList = allergyHxSubstanceListProperty.DefaultValue;
and on almost every other field in the object, but the only thing that helped the Mismatch Error was to change LoadProperty() to SetProperty() which meant not populate allergyHxSubstanceList. In SL, I never saw a Mismatch error on this object with the same exact fields at all.
Would appreciate any suggestion.
The complete error is:
An unhandled exception of type 'Csla.PropertyLoadException' occurred in Csla.dll
Additional information: Property load or set failed for property allergyHxSubstanceList (Items collection must be empty before using ItemsSource.)

PS: I rearranged my object graph and removed AllergyHxSubstanceList from AllegyHx. Everything is working fine now.
PS2: It has been said before, and I knew it and looked for it but just missed it. The AllergyHxSubstanceList is used in two different places in the UI. I checked and corrected one only. The listbox had a gratuitous . I removed it and all my troubles went away.

Javed

@javed007

This comment has been minimized.

Show comment
Hide comment
@javed007

javed007 Sep 28, 2015

How does one go about deleting an object graph when the user exits, with or without saving changes?
Javed

How does one go about deleting an object graph when the user exits, with or without saving changes?
Javed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment