To use the http authentication one has to override the GetWebRequest function and append http authorization header as follows: using System; using System.Collections.Generic; using System.Text; using System.Web.Services.Protocols; using System.Net; namespace WindowsApplication1.WebServiceAPI { public class WebServiceAPIAuth : WebServiceAPI { public string UserName; public string Password; private string S2Base(string s) { byte [] ba; ba=Encoding.ASCII.GetBytes(s); return Convert.ToBase64String(ba); } protected override System.Net.WebRequest GetWebRequest(Uri uri) { CredentialCache cc = new CredentialCache(); WebRequest wr = base.GetWebRequest(uri); wr.Headers.Add(HttpRequestHeader.Authorization, "Basic "+S2Base(UserName+':'+Password)); return wr; } } }
alabax
Posts
-
Web-service enforced authentication -
Web-service enforced authenticationHello! I have large Java application, which is controlled through web-services. Some functions are available for anonymous users, it works ok. Some functions are only for authenticated users. The service expects login credentials in the http request. The following .net code
using System; using System.Net; class Program { static void Main(string[] args) { WebServiceX.SomeAPI api = new WebServiceX.SomeAPI.SomeAPI(); api.Credentials = new NetworkCredential("MyUserName", "MyPassword"); api.PreAuthenticate = true; api.Url = "http://mysite/myapp/api"; api.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11; api.someMethod(parameter); } }
throws an exception:System.Web.Services.Protocols.SoapException: java.rmi.RemoteException: ---omitted---: CLQAHDEBUG: Permission Denied : User anonymous does not have permission ---internal method name--- in System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall ) in System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodNa me, Object[] parameters) in WebServicesConsumer2.LMSRoster.LMSRosterAPI.unrosterUsers(String[] in0) in .\WebServicesConsumer2\Web References\LMSRoster\Reference.cs:line 1 31 in WebServicesConsumer2.Program.Main(String[] args) in .\WebService sConsumer2\Program.cs:line 19
Captured communication packets do not contain any credential data. Why? How to make it work? -
difflib for .netPython has library 'difflib' which can be used to find coincidence percent between two sequences (strings). I am looking for the way to do the same (compare 2 strings) within .net platform. So what is the name for an algorithm I am looking for? And where to look for it?
-
vector<bool> can't convert to 'bool*'?Scott Meyers in his book "Effective STL" says vector is not really vector - it's a bitset and it uses proxy when you try to address an element. You cannot use it like an array. :( Try different element type instead.
-
How to convert string to wstring by means of STL and C++ headers only?I mean questions like this appear every month on the newsgroups and message boards. =)
-
Converting a wstring to UTF8?In the Microsoft stl libraries, localization uses C interface. The locale class calls setlocale function. And it cannot work with UTF-8. From the Remarks section on the setlocale function reference: "The set of available languages, country/region codes, and code pages includes all those supported by the Win32 NLS API (except code pages that require more than two bytes per character, like UTF-8)."
-
How to convert string to wstring by means of STL and C++ headers only?Ok, here comes cute solution :) wstring s2w(const string &s,const locale &loc=global_locale) { size_t l=s.length(); vector pw(l+1); use_facet>(loc).widen(&s[0],&s[l],&pw[0]); wstring ws(&pw[0]); return ws; } widen does not append trailing L'\0'! The question is: does vector always initialize values to 0?
-
How to convert string to wstring by means of STL and C++ headers only?locale global_locale; wstring s2w(const string &s,const locale &loc=global_locale) { size_t l=s.length()+1; const char *pc=s.c_str(); wchar_t *pw=new wchar_t[l]; if (pw==0) throw; use_facet>(loc).widen(pc,pc+l-1,pw); pw[l-1]=L'\0'; wstring ws(pw); delete [] pw; return ws; }
-
How to convert string to wstring by means of STL and C++ headers only?OMG! It's such a shame I did new without delete ;) GC is deep in my mind! wstring s2w(const string &s) { size_t l=s.size()+1; const char *pc=s.c_str(); wchar_t *pw=new wchar_t[l]; if (pw==0) throw; locale loc(""); use_facet>(loc).widen(pc,pc+l-1,pw); wstring ws(pw); delete [] pw; return ws; }
-
How to convert string to wstring by means of STL and C++ headers only?like this: wstring s2w(const string &s) { size_t l=s.size()+1; const char *pc=s.c_str(); wchar_t *pw=new wchar_t[l]; locale loc(""); use_facet>(loc).widen(pc,pc+l-1,pw); return wstring(pw); } -- modified at 14:03 Wednesday 12th April, 2006
-
How to convert string to wstring by means of STL and C++ headers only?that's the only ;)
-
How to convert string to wstring by means of STL and C++ headers only?Yeah once again about it! I know, there is a way to do it using crt function mbstowcs. The first thing I do not like about it I have single-byte character string (in the cp1251 encoding for example). The second it's not about stl.