Groups | Blog | Home
all groups > dotnet web services > september 2006 >

dotnet web services : Web Service method works on local machine but fails on remote


Abhi
9/25/2006 11:40:02 AM
Hi All,

I have a web service method which works fine when called from my local
machine i.e. from localhost but when I publish the web services to a remote
machine it throws an invalid cast soap exception.

That web service method access Active Directory to get the group names for
the given user. Following is the code.

DirectorySearcher dirSearcher = new DirectorySearcher();

dirSearcher.Filter = String.Format("(cn={0})", strCommonName);
dirSearcher.PropertiesToLoad.Add("MemberOf");

SearchResult result = dirSearcher.FindOne();

string group = (string)result.Properties["memberOf"][0]

It's the last line where it throws an exception,
Unable to cast object of type 'System.Byte[]' to type 'System.String'.

And this happens only when I try to use the web service method from the
remote server. It works fine when used from my local machine.

Using VS .NET 2005 to develop the web services.
The remote server is a 64 bit Windows XP machine running VS.NET 2005 runtime.

Thanks for any help!
Abhi
9/25/2006 1:35:02 PM
John,

You might be right becasue I chnaged my code to accept a byte array and then
convert it to a string as follows,

byte[] byteArray =
(byte[])result.Properties["memberOf"][counter];

string group = "";

foreach (byte t in byteArray)
{
char c = Convert.ToChar(t);
group += c.ToString();
}

and it works fine on the remote server but fails! on my machine throwing an
exception which say unavble to convert a string to byte[].

And to answer your question that byte array converted to string gives me the
group name.

How can I make it work on both machines?

Thanks,
Abhi


[quoted text, click to view]
John Saunders
9/25/2006 3:43:29 PM
[quoted text, click to view]

So, why is it returning System.Byte[]? What's in that byte array?

I suspect that memberOf has a different meaning to your local machine than
it does to your server.

John

John Saunders
9/25/2006 6:11:39 PM
[quoted text, click to view]

This is not a web services question any more. The question is, "why is
memberOf different on these two machines and how can I make it the same or
at least make it look like it's the same".

John

Abhi
9/26/2006 7:39:01 AM
Yep, this no longer remains a web service question. Initially I thought it's
the WSDL playing some tricks and not interpreting the returned object
correctly but that doesn't seems to be the case. I don't know a whole lot
about Active Directory or LDAP. Please let me know if there is a similar
discussion forum for active directory services so I can post the right
question.

Thanks for your help

-Abhi

[quoted text, click to view]
AddThis Social Bookmark Button