calling WCF service methods from JavaScript in another domain?

J

jake

Can someone please give me an example on how to call a wcf method that
resides on a different domain from JavaScript (not from C#/asp.net)?
All the examples that I have seen show how to call from the same
domain.
I don't care what the binding is. I'll use what works.
I need concrete examples or links to concrete example please. Not
just links to articles describing how to do it.
Your help is greatly appreciated.
 
D

Duy Lam

jake said:
Can someone please give me an example on how to call a wcf method that
resides on a different domain from JavaScript (not from C#/asp.net)?
All the examples that I have seen show how to call from the same
domain.
I don't care what the binding is. I'll use what works.
I need concrete examples or links to concrete example please. Not
just links to articles describing how to do it.
Your help is greatly appreciated.

We can use JavaScript to call a executable file but the security setting
of IE must be set to lowest level; and then that file can call wcf
method in turn
If you want only JavaScript can do the calling, I think you must be the
first one having that idea.
 
J

jake

We can use JavaScript to call a executable file but the security setting
of IE must be set to lowest level; and then that file can callwcf
method in turn
If you want only JavaScript can do the calling, I think you must be the
first one having that idea.

JavaScript can call methods in regular web services. Why can't it
call WCF methods as well?
I highly doubt that I am the first one to think of this.
Did everyone who used google (which has javascript calls to web
services through the XMLHttpRequest) have to have IE or any other
browser's security set to the lowest level?
The structure of the website that I am building is such that some
calls are to be made from the server (asp.net) side and some from the
client side, to save bandwidth and such, and to be efficient.
But please elaborate as to why this is such a strange thing to do (why
would I be the first one to inquire about this).
I am not being sarcastic; I really need to know if there is a better
way to do what I am doing now.
All help is greatly appreciated.
Thanks
jake
 
D

Duy Lam

jake said:
JavaScript can call methods in regular web services. Why can't it
call WCF methods as well?
I highly doubt that I am the first one to think of this.
Did everyone who used google (which has javascript calls to web
services through the XMLHttpRequest) have to have IE or any other
browser's security set to the lowest level?

When saying set the IE security to lowest levelt, I meant to use ActiveX
object (call an executable file).
You use XMLHttpRequest to a call to server, and then what thing happen
next? Does JavaScript *communicate* with WCF or wait for response from
server? If you do that, it seems there is a misunderstand about your
question.
Anyway, trying to argue about this could go nowhere. You said you used
JavaScript to trigger a calling to web server (by ajax), and it does not
mean "JavaScript call a WCF method".
The structure of the website that I am building is such that some
calls are to be made from the server (asp.net) side and some from the
client side, to save bandwidth and such, and to be efficient.
But please elaborate as to why this is such a strange thing to do (why
would I be the first one to inquire about this).
I am not being sarcastic; I really need to know if there is a better
way to do what I am doing now.
All help is greatly appreciated.
Thanks
jake

It seems you're angry about my reply. I'm sorry.
 
J

jake

jakewrote:



When saying set the IE security to lowest levelt, I meant to use ActiveX
object (call an executable file).
You use XMLHttpRequest to a call to server, and then what thing happen
next? Does JavaScript *communicate* withWCFor wait for response from
server? If you do that, it seems there is a misunderstand about your
question.
Anyway, trying to argue about this could go nowhere. You said you used
JavaScript to trigger a calling to web server (by ajax), and it does not
mean "JavaScript call aWCFmethod".


It seems you're angry about my reply. I'm sorry.

No, no; I am not angry at all. Not even in the least bit. No need to
be sorry. I am just anxious for some help. In fact, I am the one who
should be sorry for asking and replying as ambiguously as I did.

Let me try again:
I need to make AJAX work with WCF from the client's JavaScript, to
update only part of the web page instead of a full reload.
I know AJAX (XmlHttpRequest) works from the client's JavaScript to
retrieve info from regular web services and update part of the web
page.
I need to do the same thing, but with a WCF service instead of a
regular web service.
In other words:
instead of,
client ---(through Get or Post request)---> asp.net/C#/IIS ---(through
XmlHttpRequest)---> WCF service ---> asp.net/C#/IIS ---> client
I would like
client ----(through XmlHttpRequest)---> WCF service ---> client
Is this possible?

If this is still somewhat vague, let me know and I will clarify it
some more.
Thanks
jake
 
D

Duy Lam

jake said:
No, no; I am not angry at all. Not even in the least bit. No need to
be sorry. I am just anxious for some help. In fact, I am the one who
should be sorry for asking and replying as ambiguously as I did.


Yes, the misunderstand have been solved.

Let me try again:
I need to make AJAX work with WCF from the client's JavaScript, to
update only part of the web page instead of a full reload.
I know AJAX (XmlHttpRequest) works from the client's JavaScript to
retrieve info from regular web services and update part of the web
page.
I need to do the same thing, but with a WCF service instead of a
regular web service.
In other words:
instead of,
client ---(through Get or Post request)---> asp.net/C#/IIS ---(through
XmlHttpRequest)---> WCF service ---> asp.net/C#/IIS ---> client
I would like
client ----(through XmlHttpRequest)---> WCF service ---> client
Is this possible?

If this is still somewhat vague, let me know and I will clarify it
some more.
Thanks
jake


You need to build an distribution application using WCF. The client
would be a web browser, isn't it? So we only use JavaScript to get it done.
I think it is not possibility. You can look at the diagram
(http://img144.imageshack.us/img144/3391/wcfhq3.jpg), and your situation
will drop into two solutions: WSBinding or BasicBinding. To use WCF we
must get proxy from the Metadata Exchange to know the service(s) exposed
what the contract, data member and fault exception are. Although all
data always be serialized into xml string but the JavaScript can not
understand the object, data, fault which are defined for .NET in proxy.

For example: your contract will have 2 methods and 5 entities (a class
having DataContract attribute). So how can JS get to know it?

I don't know whether there is any tool for it.
 
J

jake

You need to build an distribution application usingWCF. The client
would be a web browser, isn't it? So we only use JavaScript to get it done.
I think it is not possibility.

Yes, it is a web browser.
You can look at the diagram
(http://img144.imageshack.us/img144/3391/wcfhq3.jpg), and your situation
will drop into two solutions: WSBinding or BasicBinding. To useWCFwe
must get proxy from the Metadata Exchange to know the service(s) exposed
what the contract, data member and fault exception are. Although all
data always be serialized into xml string but the JavaScript can not
understand the object, data, fault which are defined for .NET in proxy.

For example: your contract will have 2 methods and 5 entities (a class
having DataContract attribute). So how can JS get to know it?

I have not created regular web services before. I jumped straight
into WCF. I guess, first, I really need to understand how browser/
javascript can see the exposed methods of a regular web service
without a proxy. Of course, the assumption here is that WCF services
can expose their methods much the same way regular web services do;
but I guess I am wrong about that. So, back to the books I go.

Thanks,
jake
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top