473,387 Members | 1,465 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,387 software developers and data experts.

HTTP Statuscode 401 (unauthorized) when accessing secured webservice

Hi,

when accessing a secured 3rd party webservice i'm getting a 401 HTTP Statuscode (unauthorized). When entering the url in
a browser and entering the username and password manually, the wsdl is returned. So the username and password should
be ok.

I'm using this code:

Merchant myMerch = new Merchant();
myMerch.merchantIdentifier=merchantId;
myMerch.merchantName="Merchant Name";

// WSE 2.0 Webservice Interface
merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();
m_merch.Url = url;
m_merch.Credentials = new NetworkCredential(username,password);

MerchantDocumentInfo[] docs = m_merch.getAllPendingDocumentInfo(myMerch, "_GET_ORDERS_DATA_");

What can I do?

Thanks,
Anton
Jun 27 '08 #1
10 9720
Hi Anton,

From your description, you're encountering some problem when accessing an
external/3rdparty webservice in your .net application, the error is
specific to security authentication, correct?

According to the error message, it indicate some unauthenticated or
unauthorized error(401 error code). Also, in the code snippet you
provided, you have used the networkCredential class to construct a security
credentials and pass it into webservice proxy. currently, I'd like to
confirm the following things:

** when you visit the webservice asmx, is it prompting dialog for
username/password?

** that's the external webservice's authenticatino mode( integrated windows
or basic authentication) or whether it is hosted on IIS server ot not?

For .nett webservice proxy, you can use CredentialCache class to construct
client credentials and specify authenticaiton type. e.g.

#use NTLM authentication
==============
MyService.MyService ms = new MyService.MyService();

System.Net.NetworkCredential nc = new
System.Net.NetworkCredential("username","password" ,"domainame");

System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(ms.Url),"NTLM",nc);

ms.Credentials = cc;
================

Here is a former thread I've mentioned this:

#How to call a web service using NT Authentication from Web Service Options
http://groups.google.com/group/micro...es.csharp/brow
se_thread/thread/b6ccba48133cb367/3d51bc6213805828

You need to make sure what's the target service's authentication mode and
then specify the correct authentication type for your credential.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Sun, 15 Jun 2008 10:00:01 +0200
From: Anton <an***@newsgroups.nospam>
Subject: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi,

when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in
a browser and entering the username and password manually, the wsdl is
returned. So the username and password should
be ok.

I'm using this code:

Merchant myMerch = new Merchant();
myMerch.merchantIdentifier=merchantId;
myMerch.merchantName="Merchant Name";

// WSE 2.0 Webservice Interface
merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();
m_merch.Url = url;
m_merch.Credentials = new NetworkCredential(username,password);

MerchantDocumentInfo[] docs = m_merch.getAllPendingDocumentInfo(myMerch,
"_GET_ORDERS_DATA_");

What can I do?

Thanks,
Anton

Jun 27 '08 #2
Hi Steven,

thanks for you fast response. The 3rd party webservice is hosted on linux. It's not a .NET Webservice.

It uses Basic Authentication. If I'm visting the webservice url in the Webbrowser it is prompting dialog for
username/password. When i enter username and password, the wsdl is displayed in the browser.

Using the CredentialCache to specify basic authentication didn't help. I have tried this code:

System.Net.NetworkCredential nc = new
System.Net.NetworkCredential(username,password,"") ;
System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(m_merch.Url),"Basic",nc);
m_merch.Credentials = cc;


Steven Cheng [MSFT] schrieb:
Hi Anton,

From your description, you're encountering some problem when accessing an
external/3rdparty webservice in your .net application, the error is
specific to security authentication, correct?

According to the error message, it indicate some unauthenticated or
unauthorized error(401 error code). Also, in the code snippet you
provided, you have used the networkCredential class to construct a security
credentials and pass it into webservice proxy. currently, I'd like to
confirm the following things:

** when you visit the webservice asmx, is it prompting dialog for
username/password?

** that's the external webservice's authenticatino mode( integrated windows
or basic authentication) or whether it is hosted on IIS server ot not?

For .nett webservice proxy, you can use CredentialCache class to construct
client credentials and specify authenticaiton type. e.g.

#use NTLM authentication
==============
MyService.MyService ms = new MyService.MyService();

System.Net.NetworkCredential nc = new
System.Net.NetworkCredential("username","password" ,"domainame");

System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(ms.Url),"NTLM",nc);

ms.Credentials = cc;
================

Here is a former thread I've mentioned this:

#How to call a web service using NT Authentication from Web Service Options
http://groups.google.com/group/micro...es.csharp/brow
se_thread/thread/b6ccba48133cb367/3d51bc6213805828

You need to make sure what's the target service's authentication mode and
then specify the correct authentication type for your credential.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Sun, 15 Jun 2008 10:00:01 +0200
From: Anton <an***@newsgroups.nospam>
Subject: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi,

when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in
a browser and entering the username and password manually, the wsdl is
returned. So the username and password should
be ok.

I'm using this code:

Merchant myMerch = new Merchant();
myMerch.merchantIdentifier=merchantId;
myMerch.merchantName="Merchant Name";

// WSE 2.0 Webservice Interface
merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();
m_merch.Url = url;
m_merch.Credentials = new NetworkCredential(username,password);

MerchantDocumentInfo[] docs = m_merch.getAllPendingDocumentInfo(myMerch,
"_GET_ORDERS_DATA_");

What can I do?

Thanks,
Anton
Jun 27 '08 #3
Anton,
when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in a browser and
entering the username and password manually, the wsdl is returned.
So the username and password should be ok.
Take a look at the actual traffic, for instance using Fiddler
(www.fiddlertool.com).

Does the Authorization header look OK? I.e. "Authorization: Basic <some
base64-encoded stuff here>"? (Note that you can also have Fiddler decode
that base64-encoded stuff via "Tools | Text Encode/Decode...".)

--
Arnout.
Jun 27 '08 #4
Hi Arnout,

thanks for your answer.

Yes, the authorization header is ok:
Authorization: Basic YW54b25AYXVjdGl................

I have decoded the base64 stuff and it contains "username:password".

Anton
Arnout Grootveld schrieb:
Anton,
>when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in a browser and
entering the username and password manually, the wsdl is returned.
So the username and password should be ok.

Take a look at the actual traffic, for instance using Fiddler
(www.fiddlertool.com).

Does the Authorization header look OK? I.e. "Authorization: Basic <some
base64-encoded stuff here>"? (Note that you can also have Fiddler decode
that base64-encoded stuff via "Tools | Text Encode/Decode...".)
Jun 27 '08 #5
Hi Anton,

Seems there are something inconsistent with client-side webrequest and the
server-side authentication handler. Have you a local IIS environment, if
so, you can try setup a similar simple webservice which enable basic
authentication. I think your code will be correctly to pass through it.
Then, you can use some http trace tools to capture the http request and
compare the two with the linux server's to see whether there is any
difference. (is possible, you can also capture some requests sent by a
non-.NET client which can correctly consume the serivce). BTW, if possible,
I also recommend you contact the service side to verify whether there is
anything that may cause the problem at server-side.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Tue, 17 Jun 2008 00:06:55 +0200
MIME-Version: 1.0
Subject: Re: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi Arnout,

thanks for your answer.

Yes, the authorization header is ok:
Authorization: Basic YW54b25AYXVjdGl................

I have decoded the base64 stuff and it contains "username:password".

Anton
Arnout Grootveld schrieb:
Anton,
>when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in a browser and
entering the username and password manually, the wsdl is returned.
So the username and password should be ok.

Take a look at the actual traffic, for instance using Fiddler
(www.fiddlertool.com).

Does the Authorization header look OK? I.e. "Authorization: Basic <some
base64-encoded stuff here>"? (Note that you can also have Fiddler decode
that base64-encoded stuff via "Tools | Text Encode/Decode...".)
Jun 27 '08 #6
Anton <an***@newsgroups.nospamwrote in
news:em**************@TK2MSFTNGP06.phx.gbl:
Yes, the authorization header is ok:
Authorization: Basic YW54b25AYXVjdGl................

I have decoded the base64 stuff and it contains "username:password".
Hmm... What kind of "WWW-Authenticate" header does the 401 response
contain?

Also, similar to what Steven suggested: does the 3rd party whose service
you're trying to consume maybe provide a sample client you could try?

--
Arnout.
Jun 27 '08 #7
Hi Arnout,

thanks for your answer.

This is the response:
HTTP/1.0 401
Date: Sat, 14 Jun 2008 17:21:42 GMT
Server: Server
EmbeddedSOAPServer: WASP-C++ Vespa/4.6, build 2162 (Linux i686 2.6.18-8.el5a2xen #1 SMP Tue Apr 3 16:48:05 PDT 2007)
WWW-Authenticate: Basic realm="/gateway/merchant-interface-dime"
Connection: close
Content-Type: text/plain
Anton

Arnout Grootveld schrieb:

Anton <an***@newsgroups.nospamwrote in
news:em**************@TK2MSFTNGP06.phx.gbl:
>Yes, the authorization header is ok:
Authorization: Basic YW54b25AYXVjdGl................

I have decoded the base64 stuff and it contains "username:password".

Hmm... What kind of "WWW-Authenticate" header does the 401 response
contain?

Also, similar to what Steven suggested: does the 3rd party whose service
you're trying to consume maybe provide a sample client you could try?
Jun 27 '08 #8
Hi Steven,
Hi Arnout,

thanks for you answers.

The 3rd party is providing an application (without source) which uses this webservice. This application runs fine with
my credentials. So the server side should be ok.

I have captured the traffic from this application and compared it. But i couldn't find an important difference.

I also used reflector to examine the application. Here i couldn't find an important difference either. Their code seems
to be quite similiar to mine.

Anton

Steven Cheng [MSFT] schrieb:
Hi Anton,

Seems there are something inconsistent with client-side webrequest and the
server-side authentication handler. Have you a local IIS environment, if
so, you can try setup a similar simple webservice which enable basic
authentication. I think your code will be correctly to pass through it.
Then, you can use some http trace tools to capture the http request and
compare the two with the linux server's to see whether there is any
difference. (is possible, you can also capture some requests sent by a
non-.NET client which can correctly consume the serivce). BTW, if possible,
I also recommend you contact the service side to verify whether there is
anything that may cause the problem at server-side.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Tue, 17 Jun 2008 00:06:55 +0200
MIME-Version: 1.0
Subject: Re: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi Arnout,

thanks for your answer.

Yes, the authorization header is ok:
Authorization: Basic YW54b25AYXVjdGl................

I have decoded the base64 stuff and it contains "username:password".

Anton
Arnout Grootveld schrieb:
>Anton,
>>when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in a browser and
entering the username and password manually, the wsdl is returned.
So the username and password should be ok.
Take a look at the actual traffic, for instance using Fiddler
(www.fiddlertool.com).

Does the Authorization header look OK? I.e. "Authorization: Basic <some
base64-encoded stuff here>"? (Note that you can also have Fiddler decode
that base64-encoded stuff via "Tools | Text Encode/Decode...".)
Jun 27 '08 #9
Hi,

i found the solution: The webservice url was wrong.

The third party is offering services for germany and for the united states. In all documents only the us url was
mentioned, but i needed the .de url.

Thanks,
Anton

Anton schrieb:
Hi Steven,
Hi Arnout,

thanks for you answers.

The 3rd party is providing an application (without source) which uses
this webservice. This application runs fine with my credentials. So the
server side should be ok.

I have captured the traffic from this application and compared it. But i
couldn't find an important difference.

I also used reflector to examine the application. Here i couldn't find
an important difference either. Their code seems to be quite similiar to
mine.

Anton

Steven Cheng [MSFT] schrieb:
>Hi Anton,

Seems there are something inconsistent with client-side webrequest and
the server-side authentication handler. Have you a local IIS
environment, if so, you can try setup a similar simple webservice
which enable basic authentication. I think your code will be correctly
to pass through it. Then, you can use some http trace tools to capture
the http request and compare the two with the linux server's to see
whether there is any difference. (is possible, you can also capture
some requests sent by a non-.NET client which can correctly consume
the serivce). BTW, if possible, I also recommend you contact the
service side to verify whether there is anything that may cause the
problem at server-side.

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments
and suggestions about how we can improve the support we provide to
you. Please feel free to let my manager know what you think of the
level of service provided. You can send feedback directly to my
manager at: ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif

ications.

================================================= =
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
Date: Tue, 17 Jun 2008 00:06:55 +0200
MIME-Version: 1.0
Subject: Re: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi Arnout,

thanks for your answer.

Yes, the authorization header is ok:
Authorization: Basic YW54b25AYXVjdGl................

I have decoded the base64 stuff and it contains "username:password".

Anton
Arnout Grootveld schrieb:
>>Anton,

when accessing a secured 3rd party webservice i'm getting a 401 HTTP
Statuscode (unauthorized). When entering the url in a browser and
entering the username and password manually, the wsdl is returned.
So the username and password should be ok.
Take a look at the actual traffic, for instance using Fiddler
(www.fiddlertool.com).

Does the Authorization header look OK? I.e. "Authorization: Basic
<some base64-encoded stuff here>"? (Note that you can also have
Fiddler decode that base64-encoded stuff via "Tools | Text
Encode/Decode...".)
Jun 27 '08 #10
Thanks for your followup Anton,

I'm glad that you've figured out the issue. The result is really a bit
unexpected, but forunately we've got it via some tracing and research.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

--------------------
Date: Sat, 21 Jun 2008 12:08:47 +0200
From: Anton <an***@newsgroups.nospam>
Subject: Re: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice

Hi,

i found the solution: The webservice url was wrong.

The third party is offering services for germany and for the united states.
In all documents only the us url was
mentioned, but i needed the .de url.

Thanks,
Anton

Anton schrieb:
Hi Steven,
Hi Arnout,

thanks for you answers.

The 3rd party is providing an application (without source) which uses
this webservice. This application runs fine with my credentials. So the
server side should be ok.

I have captured the traffic from this application and compared it. But i
couldn't find an important difference.

I also used reflector to examine the application. Here i couldn't find
an important difference either. Their code seems to be quite similiar to
mine.

Anton

Jun 27 '08 #11

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

Similar topics

3
by: bd-chan | last post by:
I'm trying to log in to a secured web site automatically using c#. To do this I have go through a proxy server, and use SSL, and log in to the secure site with another user name and password...
2
by: hazz | last post by:
I don't get it. I have a VS2005 solution with a web service project and a windows project. The web service when tested on its own works fine. But when I add it as a web reference and refer to it my...
0
by: Daniel Kopp | last post by:
Hi! I tried to implement custom error pages using the <customErrors> directive in a web.config file. It worked fine for "simple" errors like HTTP 404, like this example: <customErrors...
2
by: Sachin | last post by:
Scenario: Machine A: ASP.NET Web UI IIS 6.0 Windows Server 2003 Impersonation Account: domain\Acct1 Machine B: ASP.NET Web Service IIS 6.0
0
by: Pasho | last post by:
hi I have been facing problem using C# webservices (secured using SSL). In my webservice(secured with SSL) It works fine if I try to access data from database through dataset. If I try to...
0
by: benboals | last post by:
Note: this is in reply to a message from August 2 which i found searching for help on my own problem. I couldn't seem to reply to it, but a friend suggested that simply using the same subject...
1
by: vineet.jsl | last post by:
Hello Everybody, i am facing some problem in accessing secured web service. i have some experience with web services but not with Secured web services. Actually what i have to do is, first, i...
0
by: jocbor | last post by:
Hi! We are calling a webservice in a third party application for integration purposes. The scenario is that messages arrive on msmq. We have a windows service (using a domain account)...
9
by: Sebastian K. | last post by:
Hi all. I am trying to get data from a 3rd party webservice. It seems the webservice is running on an iis server. Fiddler shows me: "Server: Microsoft-IIS/6.0 X-AspNet-Version: 2.0.50727...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...

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.