this occured when I called my WCF Service
as follows:
hosted WCF Service in IIS in name testWCF.
web application name is webWCF.
gave scriptreference as: http://localhost/testWCF/mywcf.svc
In JavaScript called the method GetSerivceCharge as
var x = new thetest.Backoffice.IBackofficeService();
var y = x.GetSerivceCharge(res);
function res(result) {
alert(result);
}
it results as follows:
Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'GetSerivceCharge' failed with the following error: Not Found
Server Error in '/webWCF' Application.
HTTP Error 404 - Not Found.
Isn't this a cross domain issue? I see that your WCF web service is hosted in IIS and accessible through http://localhost/testWCF/mywcf.svc while your web application is using the ASP.NET development server which means it is hosted on http://localhost:SOME_PORT/webWCF.
AFAIK, AJAX is used when you want to invoke a web service from javascript. Due to cross domain restrictions you need to have the web service and the web application hosted on the same domain, or create a some proxy/bridge that will delegate calls to the web service.
Try typing the web service URL directly into your browser's address bar and see what happens.
Maybe it's this dumb: GetSerivceCharge is misspelled. Try GetServiceCharge. And if that's not it, you should post your web method's signature.
I think you need to add a reference to your WCF in your project.
If you are using VS 2008 try adding a reference to your web service:
In solution explorer right click on your project. Then select Add Service Reference. Then click on discover in the dialog that pops up and you should be able to find your WCF service.
Related
I am trying to setup development environment to integrate Google sign-in on Android using Web Authenticator in Xamarin Essentials.
In the Web API project, same AuthController is included described in this article. It is running on https://localhost:44311/api
To call the API from emulator, API url is referenced as https://10.0.2.2:43411/api as described in this article.
Now, I am able to call the API url using await WebAuthenticator.AuthenticateAsync(apiUrl, callbackUrl)
But, when API tries to invoke Google authentication via await Request.HttpContext.ChallengeAsync(scheme);, below error is returned from Google.
Error 400: invalid_request, device-id and device-name are required for
the private IP: https://10.0.2.2:4311/signin-google
As I understand, it is expecting request originated from the server instead of IP address like https://<servername>
Whole situation comes down to be able to access the webservice using name (or localhost) to be used in both emulator and Google redirect uri.
I have web api that uses windows authentication. I've created my own Active Directory Server and a separate IIS Server. I have registered the IIS server to the domain but for some reason I'm getting a 401 issue when I use the API URL in my Javascript.
But works when using it directly from web browser
Please note that this is the same code (javascript, SQL Server, and ASP.NET Web Api) I'm developing at work. The only difference are the url for LDAP and domain. I have tried everything from changing Windows Authentication Providers. I'm just curious if I need to add my machine as a trusted to the Active Directory which I'm not sure how. I have added the Active Directory User to the IIS with Full Control but still no luck.
We are working on an internal MVC3 app that purely uses Windows Authentication. There's a view that does an AJAX call to a controller action that does some processing before calling a web service. The problem we are running into is that if Anonymous access is turned off (as in Windows Authentication is on), calling the service from the controller actions results in a 401: Unauthorized error.
We have run into a problem of the double hop issue where credentials aren't passed correctly from server to server when calling a service within a service. I'm wondering if the AJAX call is somewhat mimicing the same behavior and not transmitting the correct Windows credentials to the controller which then doesn't pass the correct credentials to the web service.
I've seen some posts that shows how to pass a username and password along with the jQuery call but nothing mentions, an effective way, to bring along Windows Authentication with it.
Has anyone run into a similar issue? We would rather not leave Anonymous access on the web service as it is somewhat sensitive data that we would like to control access to.
Do you have identity impersonation turned on as described in this question:
How to get Windows user name when identity impersonate="true" in asp.net?
A colleague did some research over the weekend and determined it may have something to do with Kerberos authentication setup on the server as well as the jQuery call. In order to get around it, we just refactored the web service into a library that the application just references. We made it a web service initially as we thought in the future this data would need to be accessed from other applications. Running into this issue, we will most likely make it into a NuGet package.
Thanks for the comments.
I am working on ASP.NET 4.0 MVC3 web application that works in intranet environment. The application makes use of Windows authentication. Its application pool is run by domain user that has spn set on a domain controller. Authentication works using Kerberos (on IE and Firefox after some additional configuration).
Now I want to upload files to sharepoint, but it's important for me to upload the file as the user currently logged in into the application (so the file is created on Sharepoint with his/her credentials).
I have the following code in ResourceExists(Uri uri) function:
'...
Dim identity As System.Security.Principal.WindowsIdentity = HttpContext.User.Identity
Dim impersonationContext = identity.Impersonate()
response = request.GetResponse()
impersonationContext.Undo()
'...
This works when running locally, but when I deploy to the server I get the exception:
System.Net.WebException: The remote server returned an error: (401) Unauthorized.\r\n at WebDav.WebDavClient.ResourceExists(Uri uri)\r\n at Website.Website.WebdavController.Upload(HttpPostedFileBase file, UploadViewModel vm)
I read something about passing on the credentials, that is not possible with NTLM, but I am sure I am using Kerberos (I checked the headers with wireshark and fiddler) and I see the following:
Authorization: Negotiate YIIFpQYGKwYBBQUCoIIFmTCCBZWgJDAiBgkqhkiC9x...
Any ideas why the impersonation does not work when running on the IIS server?
I found the answer here:
http://support.microsoft.com/kb/810572
"Kerberos does not work in a load-balanced architecture and IIS drops back to NTLM authentication. Because you cannot use NTLM for delegation, any applications or services that require delegation do not work. For more information, click the following article number to view the article in the Microsoft"
And that was exactly the case. I tried now with another machine that is not load-balanced and it works.
The only thing that still surprises me is that ImpersonationLevel of the identity is still Impersonate not Delegate...
After setting <identity impersonate="true"/> in your web.config try the following:
using (((WindowsIdentity)User.Identity).Impersonate())
using (var client = new WebClient { Credentials = CredentialCache.DefaultNetworkCredentials })
{
string result = client.DownloadString("http://sharepoint");
}
you need to configure your site correctly in IIS for impersonation to work.
see Configure ASP.NET Impersonation Authentication (IIS 7)
I'm in the process of developing some load tests for an internal web application.
The problem appears to be related to our use of Windows authentication. I can access the web application if I launch the browser and nevigate to our app. I can't, however, access the application via webrequest in my load test. It throws a 401 exception, Unauthorized.
I'm using Visual Studio 2010 Ultimate.
How do I use my Windows credentials in my load test? Any other ideas?
Select The Test Main node, and click the red marked button to set credentials
If your load testing tool doesn't have a way to specify the credentials to run under, you will have to use Windows Impersonation (just to perform your tests).
You could potentially do this in code (see here: http://www.codeproject.com/KB/cs/cpimpersonation1.aspx), but if you don't need to get fancy, it will be easier to update your web.config with the credentials to run under:
<identity impersonate="true" userName="accountname" password="password" />
This should work for any pages under the web site for which the web.config is configured.
I found this works...
request.Credentials = System.Net.CredentialCache.DefaultCredentials;