When we use the stand-alone encoder app I get prompted for authentication. I can put in my username and password and it works fine. The problem comes when we try to use the SDK to write our own encoder app that pushes to the server. I don't see a prompt, so I looked up in the Windows Media Encoder SDK and found the WMEncoder.OnAcquireCredentials.
I'm getting an error "No overload for 'OnAcquireCredentials' matches delegate" Does anyone have a code sample I could use for this?
Hi Walt,
First of all, there is an error in the Encoder SDK that ships with the product. On the WMEncoder.OnAcquireCredentials article, they provide the following Syntax:
void WMEncoder.OnAcquireCredentials( string bstrRealm, string bstrSite, out object pvarUser, out object pvarPassword, out object plFlags );
But if you go to the object browser you see the following:
WMEncoderLib._IWMEncoderEvents_OnAcquireCredentialsEventHandler._IWMEncoderEvents_OnAcquireCredentialsEventHandler(void (string, string, ref object, ref object, ref object)) So for instance, in a winforms app, I have a sample where I used the Form1_Load() to create the WMEncoder objects and set up the event handler like so:
WMEncoderLib._IWMEncoderEvents_OnAcquireCredentialsEventHandler._IWMEncoderEvents_OnAcquireCredentialsEventHandler(void (string, string, ref object, ref object, ref object))
// Create WMEncoderApp and WMEncoder objects.new WMEncoderAppClass();as WMEncoder;WMEncoder)myEncoder).OnAcquireCredentials +=new _IWMEncoderEvents_OnAcquireCredentialsEventHandler( EncoderApp = myEncoder = EncoderApp.Encoder (( OnAcquireCredentials);
// Create WMEncoderApp and WMEncoder objects.new WMEncoderAppClass();as WMEncoder;WMEncoder)myEncoder).OnAcquireCredentials +=new _IWMEncoderEvents_OnAcquireCredentialsEventHandler(
EncoderApp =
myEncoder = EncoderApp.Encoder
((
OnAcquireCredentials);
Then I created the event handler, itself. This fires whenever the server replies to the encoder with a request for credentials. You'd replace the user and pass variables with the username and password you want to provide.
public static void OnAcquireCredentials(string realm, string site,ref object user, ref object pass, ref object flags)Console.WriteLine("OnAcquireCredentials");"username";"password"; { user = pass = flags = 4;} In a production environment, I recommend NOT using the flags=4. This returns the credentials in plain text. This is useful when you're testing because you can use netmon or wireshark to see what is going on. But it's a security softpoint in a production environment. The flags are as following: Flag Description 1 Save the credentials in a persistent manner. 2 Do not cache the credentials in memory. 4 Return the credentials in plain text. 8 Credentials are for a proxy server. 10 If this flag is set when the AcquireCredentials method is called, it indicates that the calling object will encrypt the credentials. The application can return them to the caller in plain text.
public static void OnAcquireCredentials(string realm, string site,ref object user, ref object pass, ref object flags)Console.WriteLine("OnAcquireCredentials");"username";"password"; { user = pass = flags = 4;}
public static void OnAcquireCredentials(string realm, string site,ref object user, ref object pass, ref object flags)Console.WriteLine("OnAcquireCredentials");"username";"password";
{
user =
pass =
flags = 4;
}
In a production environment, I recommend NOT using the flags=4. This returns the credentials in plain text. This is useful when you're testing because you can use netmon or wireshark to see what is going on. But it's a security softpoint in a production environment. The flags are as following:
Flag
Description
1
Save the credentials in a persistent manner.
2
Do not cache the credentials in memory.
4
Return the credentials in plain text.
8
Credentials are for a proxy server.
10
If this flag is set when the AcquireCredentials method is called, it indicates that the calling object will encrypt the credentials. The application can return them to the caller in plain text.