473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Web Service method works on local machine but fails on remote

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
Sep 25 '06 #1
4 4791
"Abhi" <Ab**@discussions.microsoft.comwrote in message
news:29**********************************@microsof t.com...
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'.
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
Sep 25 '06 #2
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
"John Saunders" wrote:
"Abhi" <Ab**@discussions.microsoft.comwrote in message
news:29**********************************@microsof t.com...
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'.

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
Sep 25 '06 #3
"Abhi" <Ab**@discussions.microsoft.comwrote in message
news:09**********************************@microsof t.com...
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?
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
Sep 25 '06 #4
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 Saunders" wrote:
"Abhi" <Ab**@discussions.microsoft.comwrote in message
news:09**********************************@microsof t.com...
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?

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
Sep 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
2
by: felecha | last post by:
I'm working on a system that has a several computers that run an alerting system. There are 2 "Host" machines that have no user interface, and one "Admin" station that has an Administrator's...
3
by: Evan Camilleri | last post by:
I have a problem for a Windows Service to login on an SQL server (different machine) - neither Windows Authentication nor SQL Authentication worked. LOGIN FAILED FOR USER sa (for example). If...
8
by: Manfred Braun | last post by:
Hello All! I am writing a management application, which has to access remote machines registry via System.Diagnostics.EventLog.CreateEventSource . For each machine, I connect to, I create a...
7
by: David Laub | last post by:
I've also posted this issue to a Sun/java formum, but since it appears to be an integration issue, this may be the better place to posr: I have written a dot net/c# Web Services doesn't fully...
2
by: RdS | last post by:
Hello, I use sourcesafe and vb 2003 for my dev environment. on the sourcesafe server I also have sql2005 and reporting services installed. The web app references this sql server for db. When...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
7
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
我们现在遇到一个问题,通过wcf创建的webservice,选择windows service作为宿主,采用java作为客户端调用成功,但是无法使用asp.net ajax调用。...
2
by: Scott | last post by:
Attempting to install WCF service on stand alone 2003 server as a admin user (not administrator but user "WCF" i.e user added to local admin group). It fails with user error: The description...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.