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