By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,310 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,310 IT Pros & Developers. It's quick & easy.

Problem with directoryServices and authentication

P: n/a
Hello,
I am writing code, which will copy webServices from one IIS 6.0
webserver to another and using DirentoryServices to achieve this
purpose. And I have problems with authentication - I get an error
whenever I try to read properties of DirectoryEntry object. I had same
problems when I was using WMI, but there setting
ConnectionOptions co = new ConnectionOptions();
co.Authentication = AuthenticationLevel.PacketPrivacy;
solved the problem.
So perhaps a question would be - how can I set AuthenticationLevel to
PacketPrivacy, when I am using DirectoryServices?

Mar 6 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a

<tu****@gmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
| Hello,
| I am writing code, which will copy webServices from one IIS 6.0
| webserver to another and using DirentoryServices to achieve this
| purpose. And I have problems with authentication - I get an error
| whenever I try to read properties of DirectoryEntry object. I had same
| problems when I was using WMI, but there setting
| ConnectionOptions co = new ConnectionOptions();
| co.Authentication = AuthenticationLevel.PacketPrivacy;
| solved the problem.
| So perhaps a question would be - how can I set AuthenticationLevel to
| PacketPrivacy, when I am using DirectoryServices?
|

Check the AuthenticationTypes enum in System.DirectoryServices. If you are
binding to the IIS metadata you need at least
AuthenticationTypes.Encryption.
Willy.

Mar 6 '06 #2

P: n/a
WEll, I am using
AuthenticationType = AuthenticationTypes.Secure |
AuthenticationTypes.Signing | AuthenticationTypes.Encryption |
AuthenticationTypes.Delegation
but this does not work. Any other ideas?

Mar 6 '06 #3

P: n/a
Now I am starting to doubt that it's the authentication rpoblem....

the code just does not work....

here is the code:

public class WSMigration
{
private string srcServer,dstServer;

public WSMigration(string srcServer, string dstServer)
{
this.srcServer = srcServer;
this.dstServer=dstServer;
}

public void MigrateSettings()
{
DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + srcServer);
W3SVC.AuthenticationType = AuthenticationTypes.Encryption;
this.SearchRelatedSettings(W3SVC);
}

private void SearchRelatedSettings(DirectoryEntry ent)
{
ent.AuthenticationType = AuthenticationTypes.Encryption;
foreach (DirectoryEntry n in ent.Children)
{
n.AuthenticationType = AuthenticationTypes.Encryption;
if(n.Name.ToLower().Replace("bt","tb") != n.Name.ToLower())
{
this.CopyWithHierarchy(n);
}
}

private DirectoryEntry CopyWithHierarchy(DirectoryEntry source)
{
if (source.Parent.Name.ToLower() == "w3svc"/*srcServer.ToLower()*/)
{
DirectoryEntry par = new DirectoryEntry("IIS://" + dstServer +
"/W3SVC");
DirectoryEntry de = source.CopyTo(par);
par.CommitChanges();
return de;
}
else
{
return source.CopyTo(this.CopyWithHierarchy(source.Parent ));
}
}

public void MigrateFiles()
{
//Copies all neccesary files
}
}

I'd be very gratefull if someone could review this.

Mar 6 '06 #4

P: n/a
| the code just does not work....
is of little help here, please be more specific. Where does it fail, any
exceptions.. stacktraces..?

Willy.

"LT_Hassan" <tu****@gmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
| Now I am starting to doubt that it's the authentication rpoblem....
|
| the code just does not work....
|
| here is the code:
|
| public class WSMigration
| {
| private string srcServer,dstServer;
|
| public WSMigration(string srcServer, string dstServer)
| {
| this.srcServer = srcServer;
| this.dstServer=dstServer;
| }
|
| public void MigrateSettings()
| {
| DirectoryEntry W3SVC = new DirectoryEntry("IIS://" + srcServer);
| W3SVC.AuthenticationType = AuthenticationTypes.Encryption;
| this.SearchRelatedSettings(W3SVC);
| }
|
| private void SearchRelatedSettings(DirectoryEntry ent)
| {
| ent.AuthenticationType = AuthenticationTypes.Encryption;
| foreach (DirectoryEntry n in ent.Children)
| {
| n.AuthenticationType = AuthenticationTypes.Encryption;
| if(n.Name.ToLower().Replace("bt","tb") != n.Name.ToLower())
| {
| this.CopyWithHierarchy(n);
| }
| }
|
| private DirectoryEntry CopyWithHierarchy(DirectoryEntry source)
| {
| if (source.Parent.Name.ToLower() == "w3svc"/*srcServer.ToLower()*/)
| {
| DirectoryEntry par = new DirectoryEntry("IIS://" + dstServer +
| "/W3SVC");
| DirectoryEntry de = source.CopyTo(par);
| par.CommitChanges();
| return de;
| }
| else
| {
| return source.CopyTo(this.CopyWithHierarchy(source.Parent ));
| }
| }
|
| public void MigrateFiles()
| {
| //Copies all neccesary files
| }
| }
|
| I'd be very gratefull if someone could review this.
|
Mar 6 '06 #5

P: n/a
Oh, sorry, forgot that.
So it fails in method CopyWithHierarchy() at line "DirectoryEntry de =
source.CopyTo(par);" with

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
system.directoryservices.dll

Additional information: Exception from HRESULT: 0x80005000."
Stack trace follows:
[<Non-user Code>]
migratewebservices.dll!MigrateWebServices.WSMigrat ion.CopyWithHierarchy(System.DirectoryServices.Dir ectoryEntry source = {System.DirectoryServices.DirectoryEntry}) Line 74 + 0xd bytes C#


migratewebservices.dll!MigrateWebServices.WSMigrat ion.CopyWithHierarchy(System.DirectoryServices.Dir ectoryEntry
source = {System.DirectoryServices.DirectoryEntry}) Line 80 + 0x21
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigrat ion.CopyWithHierarchy(System.DirectoryServices.Dir ectoryEntry
source = {System.DirectoryServices.DirectoryEntry}) Line 80 + 0x21
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigrat ion.SearchRelatedSettings(System.DirectoryServices .DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 57 C#

migratewebservices.dll!MigrateWebServices.WSMigrat ion.SearchRelatedSettings(System.DirectoryServices .DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 41 + 0xec
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigrat ion.SearchRelatedSettings(System.DirectoryServices .DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 41 + 0xec
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigrat ion.SearchRelatedSettings(System.DirectoryServices .DirectoryEntry
ent = {System.DirectoryServices.DirectoryEntry}) Line 41 + 0xec
bytes C#

migratewebservices.dll!MigrateWebServices.WSMigrat ion.MigrateSettings()
Line 36 C#
TestApp.exe!TestApp.Class1.Main(string[] args = {Length=0}) Line
28 C#

Mar 6 '06 #6

P: n/a
So no ideas? I have to finish this project today, because we are having
a major serving migration tomorow, and witout this software it will be
much more work....

Mar 6 '06 #7

P: n/a

"LT_Hassan" <tu****@gmail.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
| So no ideas? I have to finish this project today, because we are having
| a major serving migration tomorow, and witout this software it will be
| much more work....
|

Are you trying to copy DirectoryEntry objects from one metabase to another,
that is on different servers? That's not possible with CopyTo, both entries
must reside within the same directory (metabase) as CopyTo acts on a single
connection.

What you need to do is re-create the same object hierarchy at the
destination, so you'll have to retrieve the objects and properties from the
source and re-create them on the dest.

Willy.
Mar 6 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.