|
We have a .Net webservice which runs on one server and a web application (javascript) running on another. The webservice needs to have Windows Authentication.
We keep getting the error 401 Unauthorized on the CORS Preflight call, which preceeds the cross domain webservice call. If we move the webservice on the same machine as the application, the calls run perfectly.
Spent four days now to get it working, hopefully someone here can point me in the right direction...
P.S.: added a JSFiddle which demonstrates the problem. http://jsfiddle.net/mr9Lpbc1/34/[^]
Here is the web.config we use for the webservice
="1.0"="UTF-8"
<configuration>
<appSettings />
<connectionStrings />
<system.web>
<compilation debug="true" />
<authentication mode="Windows" />
<customErrors mode="Off" />
<webServices>
<protocols>
<add name="HttpSoap" />
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
<httpRuntime maxUrlLength="9999" relaxedUrlToFileSystemMapping="true" maxQueryStringLength="2097151" requestValidationMode="2.0"/>
<pages validateRequest="false" />
</system.web>
<system.webServer>
<defaultDocument>
<files>
<remove value="default.aspx" />
<remove value="Default.asp" />
<remove value="index.html" />
<remove value="iisstart.htm" />
<remove value="index.htm" />
<remove value="Default.htm" />
<add value="webservice.asmx" />
</files>
</defaultDocument>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://domain.nl" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="SOAPAction, Content-Type,Authorization" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="9999" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
Here is the peace of javascript we are using
SOAPClientParameters = (function () {
function SOAPClientParameters() {
var self = this;
self.list = new Array();
}
SOAPClientParameters.prototype.add = function (name, value) {
var self = this;
self.list[name] = value;
return self;
};
SOAPClientParameters.prototype._serialize = function (o) {
var s = "";
switch (typeof (o)) {
case "string":
s += o;
case "number":
case "boolean":
s += o.toString(); break;
case "object":
if (testNull(o)) { s += ""; }
else if (typeof o === 'Date') {
dateToSqlString(o);
}
else if (typeof o === 'Array') {
for (var p in o) {
if (!isNaN(p))
{
(/function\s+(\w*)\s*\(/ig).exec(o[p].constructor.toString());
var type = RegExp.$1;
switch (type) {
case "":
type = typeof (o[p]);
case "String":
type = "string"; break;
case "Number":
type = "int"; break;
case "Boolean":
type = "bool"; break;
case "Date":
type = "DateTime"; break;
}
s += "<" + type + ">" + SOAPClientParameters._serialize(o[p]) + "</" + type + ">"
}
else
s += "<" + p + ">" + SOAPClientParameters._serialize(o[p]) + "</" + p + ">"
}
}
else
for (var p in o)
s += "<" + p + ">" + SOAPClientParameters._serialize(o[p]) + "</" + p + ">";
break;
default:
throw new Error(500, "SOAPClientParameters: type '" + typeof (o) + "' is not supported");
}
return s;
}
SOAPClientParameters.prototype.toXml = function () {
var self = this;
var xml = "";
for (var p in self.list) {
if (typeof self.list[p] !== 'function') {
xml += "<" + p + ">" + self._serialize(self.list[p]) + "</" + p + ">";
}
}
return xml;
}
return SOAPClientParameters;
}());
SOAPClient = (function () {
function SOAPClient(url, async) {
var self = this;
self.xmlHttp = null;
if (window.XMLHttpRequest) {
self.xmlHttp = new XMLHttpRequest();
if (self.xmlHttp.readyState == null) {
self.xmlHttp.readyState = 1;
self.xmlHttp.addEventListener("load",
function () {
self.xmlHttp.readyState = 4;
if (typeof self.xmlHttp.onreadystatechange == "function")
self.xmlHttp.onreadystatechange();
},
false);
}
} else {
throw 'This browser is not supported!';
}
self.xmlHttp.async = async;
if (self.xmlHttp !== null) {
self.xmlHttp.open("POST", url, self.xmlHttp.async);
self.xmlHttp.url = url;
self.xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
self.xmlHttp.onerror = function () {
if (self.xmlHttp.async) {
var errorClient = new SOAPClient(self.xmlHttp.url, false);
var exception = errorClient.invoke(self.xmlHttp.func, self.xmlHttp.parameters, function () { }, function () { });
self.xmlHttp.errorCallback(isnull(exception.message, 'Unknown error...'));
}
}
self.xmlHttp.onload = function () {
if ((self.xmlHttp.readyState === 4) && (self.xmlHttp.status !== 200)) {
self.xmlHttp.errorCallback(self.xmlHttp.statusText);
}
}
}
}
SOAPClient.prototype.result = function (data) {
return data;
};
SOAPClient.prototype.invoke = function (method, parameters, successCallback, errorCallback) {
var self = this;
var ns = 'http://domain.com/';
var sr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<" + method + " xmlns=\"" + ns + "\">" +
parameters.toXml() +
"</" + method + "></soap:Body></soap:Envelope>";
var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
self.xmlHttp.function = method;
self.xmlHttp.parameters = parameters;
self.xmlHttp.errorCallback = errorCallback;
self.xmlHttp.setRequestHeader("SOAPAction", soapaction);
if (self.xmlHttp.async) {
self.xmlHttp.onreadystatechange = function () {
if ((self.xmlHttp.readyState == 4) && (self.xmlHttp.status === 200)) {
self.onSuccess();
}
}
}
try {
self.xmlHttp.send(sr);
if (!self.xmlHttp.async) {
self.onSuccess();
}
} catch (ex) {
return ex;
}
}
SOAPClient.prototype.onSuccess = function () {
var self = this;
if ((self.xmlHttp.readyState == 4) && (self.xmlHttp.status === 200)) {
var o = null;
var responseText = self.xmlHttp.response;
}
}
return SOAPClient;
}());
modified 9-Oct-14 8:03am.
|
|
|
|
|
|
|
struggling to figure out this program. beginner javascript programmer.
My task is to write a program that does this: Stores the 50 states' names and capitals in two arrays (which I have).
Uses the window.prompt() method to display a state name, asks the user to enter the matching capital name, and tells the user that entering "exit" will stop the program.
Checks the user input and use the window.prompt() method to tell the user if the answer is correct or not. At the same time, the window.prompt() method displays the next state name, and asks the user to enter the next matching capital name. Please note that giving the user feedback and prompting the user to try the next are done with the same window.prompt().
Uses a loop to go through all 50 states until all 50 states have been displayed or the user enters "exit".
Any guidance would be much appreciated. Even just getting pointed in the right direction. I've read through many tutorials and just can't seem to get it. Thank you.
|
|
|
|
|
Post only once please!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
struggling to figure out this program. beginner javascript programmer.
My task is to write a program that does this: Stores the 50 states' names and capitals in two arrays (which I have).
Uses the window.prompt() method to display a state name, asks the user to enter the matching capital name, and tells the user that entering "exit" will stop the program.
Checks the user input and use the window.prompt() method to tell the user if the answer is correct or not. At the same time, the window.prompt() method displays the next state name, and asks the user to enter the next matching capital name. Please note that giving the user feedback and prompting the user to try the next are done with the same window.prompt().
Uses a loop to go through all 50 states until all 50 states have been displayed or the user enters "exit".
Any guidance would be much appreciated. Even just getting pointed in the right direction. I've read through many tutorials and just can't seem to get it. Thank you.
|
|
|
|
|
Member 11116351 wrote: My task So start do it! Do not wait for us to do it for you! Thing are work a bit differently. YOU came with some (probably imperfect) solution and WE help you make it work...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
|
Please do not post same question multiple times
|
|
|
|
|
I tried the ckEditor forum but I was listed as a spammer and denied a post, until they resolve it.
Any body here know much about ckEditor Custom Plugins, and the element ID system?
[SOLVED]
Well the ckEditor forum was no help either. But I figured it out the next day.
modified 26-Sep-14 17:53pm.
|
|
|
|
|
Hi,
I am gonna start a new web application which gives more importance to client side rather than server side. So we have so many technologies to achieve the client side scripting. eg :- JQuery,JavaScript,Angular JS. Among these which one should i use for my project?
Thanks In Advance
Sibeesh
|
|
|
|
|
you can start with jQuery.
Vindhyachal Kumar
|
|
|
|
|
Ok thanks for your reply.
|
|
|
|
|
0) Forget Javascript.
1) Go with jQuery which is better than Javascript.
2) If you don't believe, do Google search for "Javascript vs jQuery"
3) AngularJs is a javascript library like jQuery but it's also framework. Some people use Angular to create SPA.
Here a CP article. 10 Reasons Web Developers Should Learn Angular[^]
and one more post. 10 Reasons Why You Should Use AngularJS[^]
If you want to perform just client side operations, go with jQuery which is more than enough. And it'd be better to learn jQuery before start learning other javascript libraries like AngularJs, KnockOutJs, etc.,
|
|
|
|
|
thatraja wrote: Go with jQuery which is better than Javascript. jQuery IS javascript.
But yes, it is an easier way to use JavaScript.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
Thank you Those links are useful
|
|
|
|
|
Advice like this will get me very confusing. First, JavaScript is a language. Second jQuery and AngularJS are libraries developed using JavaScript.
|
|
|
|
|
Agree with you. I just suggested OP to go with jQuery instead of javascript. Still there're many people fighting with old javascript code. Hereafter I'll add more details to avoid things like this. Thank you.
|
|
|
|
|
I suggest at least using the jQuery library but of course you'll want to design out your app first and make sure just the jQuery library can handle it properly.
For example, if you'll have grids then you'll likely want a separate library like jqGrid or something.
The point is your requirements and your current experience combined with your ability to learn new libraries should drive what you end up using.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I know JQuery, but i dont have much experience in Angular JS. And i can learn new technologies in a faster way. i love to learn those . Thanks a lot for your reply.
|
|
|
|
|
|
So you master all this client side scripting
|
|
|
|
|
|