Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / September 2006

Tip: Looking for answers? Try searching our database.

Web Service method works on local machine but fails on remote

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Abhi - 25 Sep 2006 19:40 GMT
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
John Saunders - 25 Sep 2006 20:43 GMT
> Hi All,
>
[quoted text clipped - 18 lines]
> It's the last line where it throws an exception,
>   Unable to cast object of type 'System.Byte[]' to type 'System.String'.

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
Abhi - 25 Sep 2006 21:35 GMT
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

> > Hi All,
> >
[quoted text clipped - 25 lines]
>
> John
John Saunders - 25 Sep 2006 23:11 GMT
> John,
>
[quoted text clipped - 22 lines]
>
> How can I make it work on both machines?

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 - 26 Sep 2006 15:39 GMT
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

> > John,
> >
[quoted text clipped - 28 lines]
>
> John

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.