TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
dilipkumar regana
1.6k
90
31.6k
cross domain wcf service using Jquery
Aug 12 2013 9:46 AM
Hai,
How to
Call cross domain wcf service using Jquery
Reply
Answers (
3
)
0
john abraham
0
2
0
Aug 23 2013 7:43 AM
you can call it using ajax call. see this link where you can find example of
cross-domain service call
0
Avinash Patil
0
22
1.2k
Aug 16 2013 5:51 AM
Here is solution :
- By using XMLHttpRequest connect to cross domain wcf service.
- Pass the parameters using the xhr.send() method.
function
createCORSRequest(method, url) {
var
xhr =
new
XMLHttpRequest();
if
(
"
withCredentials"
in
xhr)
{
xhr.open(method, url,
true
);
}
else
if
(
typeof
XDomainRequest !=
"
undefined"
) {
xhr =
new
XDomainRequest();
xhr.open(method, url);
}
else
{
xhr =
null
; }
return
xhr; }
function
CORSURL()
{
var
val = document.getElementById(
'
val'
).value;
var
url =
"
http://Service1.svc/UserRegistration"
;
var
passVal =
new
Object();
passVal.FirstNmae=
"
Avinash"
;
passVal.LastName=
"
Patil"
;
passVal.EmailId=
"
Email"
;
var
jsonText2 = JSON.stringify(passVal) ;
var
xhr = createCORSRequest(
'
POST'
, url);
if
(!xhr) { alert(
'
CORS not supported'
);
}
xhr.onload =
function
()
{
var
text = xhr.responseText;
var
result=JSON.Parse(xhr.responseText);
//
access object values using property name
alert(text+
"
!!!@"
);
};
xhr.onerror =
function
() { alert(
'
there is an error.'
); }; xhr.setRequestHeader(
'
Content-Type'
,
'
application/json'
) ;
xhr.send(jsonText2);
}
*** Need to add an headers for your service on server :
Name : Value
--------------------------------------------------------
Access-Control-Allow-Credentials : true
Access-Control-Allow-Headers : content-type
Content-Type : application/json
Access-Control-Allow-Methods : GET,POST,OPTIONS
Access-Control-Allow-Origin : *
Access-Control-Max-Age : 100000
---------------------------------------------------------
These headers need to set in web.config file of your wcf service.
or you can use IIS to set these headers . In IIS in feature view you will see 'Http Response Headers' where you need to set these headers.
--Avinash
0
Mahesh Chand
1
269.7k
240.4m
Aug 12 2013 3:04 PM
What do you mean by cross domain? If you have a WCF service, it can be available from any application if hosted publicly. So it does not matter from where you call it.
how to get 64bit data string from iphone in wcf restfull web
How to learn WCF & WPF?