views:

746

answers:

3

I'm attempting to push notifications to my iPhone, which I've successfully done using PHP. However, I'm unable to open a socket connection to Apple's push servers using C#. I don't think there's a problem with the certificate itself, since I'm able to successfully push notifications using this code in PHP:

$ctx = stream_context_create();

stream_context_set_option($ctx, 'ssl', 'local_cert', 'cert.pem');

$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

fwrite($fp, $msg);

When I try to authenticate in C# using the code below, Apple closes the connection right away. I get this exception: "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Default, false);

I basically took all my code from this question: http://stackoverflow.com/questions/1056083/c-iphone-push-server

I thought it might be a problem with the certificate since I don't think C# allows you to just load .PEM files programmatically. I used OpenSSL to convert it to a .PFX file, but I still have the same problem.

Any idea how I can troubleshoot this (possible certificate) problem?

A: 

This actually turned out to be a problem with .NET 2.0. Not sure exactly what it is, but I compiled in Visual Studio 2008 and everything worked great.

Brandon
A: 

Hi,

Can anyone help me in knowing, how to install SSL Certificates on a remote server, for implementing APNS for the App to be submitted by to Appstore.

I mean, does the downloading .pem file and transferring to remote server would work. if so, please let me know the process or any commands to be executed.

Thank u.

Pramod Jain
A: 

Can you send me sample code for .net Push notification..?

ketan