@slace - I really hope thats not the case. Well I am going to try it out tomorrow. I will let you know if it works or not. If it doesnt work, you think I have no choice but to convert it to a asmx?
Interface: <ServiceContract()> Public Interface ITest
<WebGet(ResponseFormat:=WebMessageFormat.Json)> <OperationContract()> Function Test(ByVal vFName As String) As ServiceResponse End Interface
Implementation:
Imports System.Runtime.Serialization
Public Class Test Implements ITest
Public Function Test1(ByVal vFName As String) As ServiceResponse Implements ITest.Test Dim lResponse As New ServiceResponse lResponse.x = "Hello my name is: " & vFName Return lResponse End Function End Class
<DataContract()> Public Class ServiceResponse <DataMember()> Public x As String End Class
ok we got it to work. the reason it was not working is because the page calling this webservice was secure and the webservice itself was not. to fix this we secured our webservice end point in the web.config file.
Calling a web service (.svc) from jquery in Umbraco
Hey guys,
I need help doing the following. I searched the forums and couldnt find the correct answer.
1. I have a webservice that saves a piece of data and returns JSON, with the values that were saved
2. This save is called from a jquery script that then uses the return JSON object and displays the values on the screen
3. The webservice is ready to go
4. I know how to call a webservice from jquery. What I dont know is what changes I have to make to the config files to call this webservice.
Thanks in advance for the help
Vijay
Hi Vijay,
In my experience you don't need any additional configuration to call a web service.
What I often do however is add an URL rewriting rule in config/UrlRewriting.config, which allows for clean url's in Jquery:
<add name="AccountService"
virtualUrl="^~/account/newpassword"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/webservices/AccountService.asmx/RequestNewPassword"
ignoreCase="true"
/>
$.ajax
({
type: "POST",
url: "/account/newpassword",
data: ..
});
I haven't seen anyone get a WCF service working in Umbraco, only ASMX. It seemed to be some problem with the way WCF hosts itself :/
@Lennart - Thank you for your quick reply
@slace - I really hope thats not the case. Well I am going to try it out tomorrow. I will let you know if it works or not. If it doesnt work, you think I have no choice but to convert it to a asmx?
Ok here is what I have so far:
Webservice
Imports System.ServiceModel
Imports System.ServiceModel.Web
Interface:
<ServiceContract()>
Public Interface ITest
<WebGet(ResponseFormat:=WebMessageFormat.Json)>
<OperationContract()>
Function Test(ByVal vFName As String) As ServiceResponse
End Interface
Implementation:
Imports System.Runtime.Serialization
Public Class Test
Implements ITest
Public Function Test1(ByVal vFName As String) As ServiceResponse Implements ITest.Test
Dim lResponse As New ServiceResponse
lResponse.x = "Hello my name is: " & vFName
Return lResponse
End Function
End Class
<DataContract()>
Public Class ServiceResponse
<DataMember()>
Public x As String
End Class
ClientCall
$.ajax({
type: "POST",
url: "~/services/MyService.svc/Test",
data:"{'FName':'vijay'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg){alert(msg);},
error:function(msg){alert('failed');}
});
It alerts "null", but does go to the success function. What am I missing? ( I even tried msg.x, and thats not working either.)
Have you put a break point into the service to ensure it is called properly?
Have you looked into it with something like Charles or Fiddler?
Hi Vijay,
In ASP.NET 3.5 JSON serialization, the JSON response is encapsulated within a parent object to address a security vulnerability.
The parent object is a variable named "d". Does alert(msg.d) work for you?
ok we got it to work. the reason it was not working is because the page calling this webservice was secure and the webservice itself was not. to fix this we secured our webservice end point in the web.config file.
This site helped us solve the problem: http://www.myviewstate.net/blog/post/2010/02/26/Make-cross-domain-Ajax-requests-with-jQuery.aspx
@Stoop: I am not able to get the rewriting to work....how should the virtualUrl and destinationUrl look if I have a lot of querystring params?
example :
lets say the actual webservice i want to call is : https://servername/services/service.svc?param1=val1¶m2=val2¶m3=val3
If you wish to include parameters, try setting the rewriteUrlParameter to "IncludeQueryStringForRewrite".
I have not tested this one but it should be close to working:
<add name="MyServiceRedirect"
virtualUrl="^https\://servername/myservice"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="https://servername/services/service.svc"
ignoreCase="true" />
Calls to https://servername/myservice?param1=val1¶m2=val2¶m3=val3
should than be redirected to https://servername/services/service.svc?param1=val1¶m2=val2¶m3=val3
Thanks a lot it worked:)
is working on a reply...