TReKiE / msnp-sharp

Automatically exported from code.google.com/p/msnp-sharp
0 stars 0 forks source link

Web Application issue with MSNPSharp #164

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi all developers. I have tried to use the library to develop a simple
(just connect to msn) using .NET windows application and it just works
perfectly fine.

The problem occur when I use the same code for web application, it turn out
for nothing. I try to debug it but it just couldn't sign on to MSN.
Connection is established but messenger.nameserver.isSigned is just simply
never return true. 

Is there anyone do not mind to throw time and help?

Simple Code :
private Messenger messenger = new Messenger();

        public MSNController()
        {
            messenger.Credentials = new Credentials("email", "password");
            messenger.Connect();

            while (messenger.Owner.Status != PresenceStatus.Online)
            {
                if (messenger.Nameserver.IsSignedIn == true)
                {
                    Nameserver_SignedIn(); // never triggered
                }
            }

        }

Cheers!

Original issue reported on code.google.com by maryanto...@gmail.com on 11 Nov 2009 at 8:09

GoogleCodeExporter commented 9 years ago
This was worked in the first version 1.0.0 but not the latest version. I wonder 
if
there is any code need to be modified?

Original comment by maryanto...@gmail.com on 11 Nov 2009 at 8:26

GoogleCodeExporter commented 9 years ago
I'll see about this, for now. Hopefully I can get something out of this, with 
the 
limited time.

Original comment by electk...@gmail.com on 11 Nov 2009 at 8:46

GoogleCodeExporter commented 9 years ago
checked on other 2 stable version. 2.5.0 and 2.0.5 both are working fine..

Original comment by maryanto...@gmail.com on 11 Nov 2009 at 8:51

GoogleCodeExporter commented 9 years ago
Thanks for the information. I will see what I can do; now I'm just testing it 
currently.

Original comment by electk...@gmail.com on 11 Nov 2009 at 8:59

GoogleCodeExporter commented 9 years ago
If possible, which version are you using which isn't working?

Original comment by electk...@gmail.com on 11 Nov 2009 at 8:59

GoogleCodeExporter commented 9 years ago
I've tried on the latest 3.0 ++ are not working

Original comment by maryanto...@gmail.com on 11 Nov 2009 at 9:02

GoogleCodeExporter commented 9 years ago
Okay, I'll see about it now. I'll attempt and see the reasoning for it. Thanks 
for the 
report.

Original comment by electk...@gmail.com on 11 Nov 2009 at 9:04

GoogleCodeExporter commented 9 years ago
Thanks for the help..

Original comment by maryanto...@gmail.com on 11 Nov 2009 at 9:09

GoogleCodeExporter commented 9 years ago
A you sure 2.5.0 can work? I think all of the version can't work because it 
needs to 
write files on the harddisk of client side, web app just don't have the 
permission.

Original comment by freezing...@gmail.com on 11 Nov 2009 at 9:43

GoogleCodeExporter commented 9 years ago
yes it is work on mine.. I wonder why..

Original comment by maryanto...@gmail.com on 11 Nov 2009 at 10:02

GoogleCodeExporter commented 9 years ago
Same thing with me, under version 3.0.0 work, but this one doesn't work at all. 
I'm 
conering to this problem, using both versions to compare.

Original comment by electk...@gmail.com on 11 Nov 2009 at 10:06

GoogleCodeExporter commented 9 years ago
I got to do something else now, but I got some ideas from where this exception 
is 
coming from (I think):

NSMessageHandler, with the protected virtual void "OnUSRReceived". I'll try to 
do more 
research tomorrow, I'm not sure why it would cause this problem with the 
comparisons 
also.

Original comment by electk...@gmail.com on 11 Nov 2009 at 10:14

GoogleCodeExporter commented 9 years ago

Original comment by freezing...@gmail.com on 11 Nov 2009 at 2:46

GoogleCodeExporter commented 9 years ago
 while (messenger.Owner.Status != PresenceStatus.Online)
 {
    if (messenger.Nameserver.IsSignedIn == true)
    {
        Nameserver_SignedIn(); // never triggered
    }
 }

messenger.Nameserver.IsSignedIn is always false, because you must set owner 
precence:
Owner.Status = Online...

Original comment by hepha...@gmail.com on 11 Nov 2009 at 3:16

GoogleCodeExporter commented 9 years ago
Here is the code:

messenger = new Messenger();
messenger.Credentials = new Credentials("account", "pw");
messenger.Connect();

while (messenger.ContactService.AddressBookSynchronized == false)
{
                Thread.Sleep(100);
                Application.DoEvents();
}

messenger.Owner.Status = PresenceStatus.Online;

Original comment by hepha...@gmail.com on 11 Nov 2009 at 3:34

GoogleCodeExporter commented 9 years ago
Are you trying on windows application?
It works fine on windows application but not on web.

my point is that why in web application the event of 
messenger.Nameserver.SignedIn
never triggered?

Original comment by maryanto...@gmail.com on 12 Nov 2009 at 1:50

GoogleCodeExporter commented 9 years ago
Place a break point at line 1058 of NSMessageHandler.cs: 
OnAuthenticationErrorOccurred(e); and see what happend.

Original comment by freezing...@gmail.com on 12 Nov 2009 at 5:27

GoogleCodeExporter commented 9 years ago
Hello there maruantoLiauw,

With tests from a web application from what you wrote (with a few changes), I 
breakpointed a couple of areas (thanks to freezingsoft) and eventually I got 
this 
exception:

"Asynchronous operations are not allowed in this context. Page starting an 
asynchronous operation has to have the Async attribute set to true and an 
asynchronous operation can only be started on a page prior to PreRenderComplete 
event."

Assuming with the changes of code, try this and see how it goes. I've added a 
tutorial which can help you turn on the Async option:

http://littletalk.wordpress.com/2008/06/05/asynchronous-operations-are-not-allow
ed-
in-this-context-page-starting-an-asynchronous-operation-has-to-have-the-async-
attribute-set-to-true-and-an-asynchronous-operation-can-only-be-started-on-a-pag
e/

Original comment by electk...@gmail.com on 12 Nov 2009 at 10:14

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Might be better to copy that link instead of pressing it, sorry if it appears 
broken :(

Original comment by electk...@gmail.com on 12 Nov 2009 at 10:16

GoogleCodeExporter commented 9 years ago
I have tried, but nothing help as well. It works perfectly on version 2.0.5.. 
Weird
though. 

Original comment by maryanto...@gmail.com on 13 Nov 2009 at 3:07

GoogleCodeExporter commented 9 years ago
That is because in 2.0.5 we use sync method to request a security token key for 
your 
password authentication. But in 3.0, we use async method to avoid blocking the 
UI. 
Maybe you need to write a background system to login, don't use this directly 
on the 
web page.

Original comment by freezing...@gmail.com on 13 Nov 2009 at 4:04

GoogleCodeExporter commented 9 years ago
By the way, you said 2.0.5 can work, can you get your contact list after login? 
I 
think in 2.0.5 you also can't get your contct list.

Original comment by freezing...@gmail.com on 13 Nov 2009 at 4:08

GoogleCodeExporter commented 9 years ago
Yes, I can. It works fine in 2.0.5 version. 

Original comment by maryanto...@gmail.com on 16 Nov 2009 at 3:59

GoogleCodeExporter commented 9 years ago

Original comment by hepha...@gmail.com on 16 Nov 2009 at 11:13

GoogleCodeExporter commented 9 years ago
Hmm... I will see about this; I will try to look upon it, despite being busy.

Original comment by electk...@gmail.com on 16 Nov 2009 at 11:37

GoogleCodeExporter commented 9 years ago
I got a workaround for this if it can help.
{
System.Timers.Timer timer;

timer = new System.Timers.Timer(1);
timer.AutoReset = false;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Start();

while (messenger.Owner.Status != PresenceStatus.Online)
 {
    if (messenger.Nameserver.IsSignedIn == true)
    {
        Nameserver_SignedIn(); // never triggered
    }
 }

}

void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    messenger.Connect();
}

Original comment by cheng....@gmail.com on 5 Nov 2010 at 12:41

GoogleCodeExporter commented 9 years ago
Can you give us more detail? If it is proved to work, maybe we can add a wiki 
for your solution.

Original comment by freezing...@gmail.com on 5 Nov 2010 at 1:44

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
And this code is better

System.Threading.Thread thread = new System.Threading.Thread(messenger.Connect);
thread.Start();

while (messenger.Owner.Status != PresenceStatus.Online)
 {
    if (messenger.Nameserver.IsSignedIn == true)
    {
        Nameserver_SignedIn(); // never triggered
    }
 }

it looks like you are using async connection, which can't be use in same thread 
of .net web pages. So, if I start the connection in another thread, it will be 
ok.

Original comment by cheng....@gmail.com on 12 Nov 2010 at 1:49