Error while calling wcf service using JQuery.

Posted by Allemahesh under WCF on 8/22/2013 | Points: 10 | Views : 1039 | Status : [Member] [MVP] | Replies : 0
I have created an WCF service and hosted on IIS server. I am calling this service using JQuery. When I called the service using JQuery, it is going to error function and in alert there is empty message.

Calling service form .aspx page.

<script src="Script/jquery-1.10.2.min.js" type="text/javascript"></script>

<script type="text/javascript" language="javascript">
function callService()
{
var value = 10;
$.ajax({
type: "POST",
url: "http://localhost/IISWCF/GetData",
contentType: "application/json; charset=utf-8",
data: '{"value": "' + value + '"}',
dataType: "json",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("error: " + errorThrown);
},
success: function(msg) {
alert(msg.d);
}
});
}
</script>

<script type="text/javascript" language="javascript">
$(document).ready(function(){
callService();
})
</script>


Service1.svc file

namespace WcfService1
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}

}
}


IService1.cs file

namespace WcfService1
{
[ServiceContract]
public interface IService1
{

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here
}
}

Please help me to resolved this issue.




Responses

(No response found.)

Login to post response