doctor069
asked on
Trying to get WCF to return jsonp
Hi -
I am working with .net 4.0 and trying to get WCF to return jsonp for cross domain support.
The code below returns: {"d":"tester({\"body\":\"C at\"})"}
I think it needs to return: tester({""body"":""Cat""}) in order for it to work!
I get the jquery error: invalid label {"d":"tester({\"body\":\"C at\"})"}
Any help would be appreciated
I am working with .net 4.0 and trying to get WCF to return jsonp for cross domain support.
The code below returns: {"d":"tester({\"body\":\"C
I think it needs to return: tester({""body"":""Cat""})
I get the jquery error: invalid label {"d":"tester({\"body\":\"C
Any help would be appreciated
----web service code---------------
<OperationContract()> _
<WebGet(ResponseFormat:=WebMessageFormat.Json)> _
Public Function HelloGTown() As String
Dim sss As String = "tester({""body"":""Cat""})"
Return sss
End Function
----jquery code ---------
$.ajax({
type: 'GET',
url: 'http://remotedomain.example.com/service.svc/HelloGTown?callback=tester',
dataType: "jsonp",
jsonpCallback: "tester",
success: function (msg) {
alert('OK:');
},
error: function (msg) {
alert('Error');
}
});
check the interface section here (things about JSONPBehavior) : http://jasonkelly.net/2009/05/using-jquery-jsonp-for-cross-domain-ajax-with-wcf-services/
ASKER
Hi-
Have a look at the. As I understand it this is for .net 2.0. The .net 4.0 has jsonp support.
using:
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEn abled="fal se" defaultOutgoingResponseFor mat ="Json" crossDomainScriptAccessEna bled="true "/>
</webHttpEndpoint>
Have a look at the. As I understand it this is for .net 2.0. The .net 4.0 has jsonp support.
using:
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEn
</webHttpEndpoint>
create class
somthing like this
<DataContract> _
Public Class Cat
<DataMember> _
Public Property Cat() As String
Get
Return m_Cat
End Get
Set
m_Cat = Value
End Set
End Property
Private m_Cat As String
End Class
and
<WebGet(ResponseFormat:=We bMessageFo rmat.Json) > _
Public Function HelloGTown() As Cat
Dim cat As Cat = here create instance of CAT with string Cat property Return catAs
End Function
somthing like this
<DataContract> _
Public Class Cat
<DataMember> _
Public Property Cat() As String
Get
Return m_Cat
End Get
Set
m_Cat = Value
End Set
End Property
Private m_Cat As String
End Class
and
<WebGet(ResponseFormat:=We
Public Function HelloGTown() As Cat
Dim cat As Cat = here create instance of CAT with string Cat property Return catAs
End Function
use: http://jsonlint.com/
to validate
change your sss string to something like this:
to validate
change your sss string to something like this:
{
"tester": {
"body": "cat"
}
}
and this http://api.jquery.com/jQuery.ajax/
ASKER
Hi - Same issue...
See code below... returns
{"d":{"__type":"Cat:#","bo dy":"Cat"} }
See code below... returns
{"d":{"__type":"Cat:#","bo
<DataContract()> _
Public Class Cat
<DataMember()> _
Public Property body() As String
Get
Return m_body
End Get
Set(ByVal value As String)
m_body = value
End Set
End Property
Private m_body As String
End Class
<WebGet(ResponseFormat:=WebMessageFormat.Json)> _
Public Function HelloGTown() As Cat
Return New Cat() With { _
.body = "Cat"}
End Function
ASKER
Hi - disrupt that example is json not jsond. If I use json on the same domain i works but I am trying to use jsond on a different domain (cross domain support)
you should be able to do something like so:
jQuery.getJSON(url+"&callback=?", function(data) {
alert(data.Body);
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much!
I spent all day trying to get it working.
My problem was the web.config setup!
I can stop banging my head against the wall!
I spent all day trying to get it working.
My problem was the web.config setup!
I can stop banging my head against the wall!