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

HTTP Statuscode 401 (unauthorized) when accessing secured webservice

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.