i have simple wcf , i dont know how to test it throw calling my function with browser?
this is my service :
using System.ServiceModel.Activation;
namespace MYWcfService
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData()
{
return string.Format("You entered: ");
}
}
}
and this is my interface :
namespace MYWcfService
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(UriTemplate = "GetData",
Method = "Post",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetData();
}
}
and this is my web.config :
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheFor10Seconds" duration="10" varyByParam="none"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="MYWcfService.Service1">
<endpoint address="" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="MYWcfService.IService1"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
and this is service markup :
<%@ ServiceHost Language="C#" Debug="true" Service="MYWcfService.Service1" CodeBehind="Service1.svc.cs" %>
when i run the service project in .net, IIS manager will run but because it is the webhttpbinding , it cant show my service.
i write in browser ""
http://localhost/Service1.svc/GetData[
^]
but it shows nothing.
i dont know myservice is work or not.
i want to call this service from html like this :
<pre lang="HTML">
<html>
<head>
<title>JSONP Service Client Page</title>
<script type="text/javascript" ></script>
<script src="JS/JQuery.js" type="text/javascript"></script>
<script src="jquery-1.7.2.js"></script>
<script type="text/javascript">
function WCFJSON() {
type = "POST";
url = "http://Localhost/Service1.svc";
methodName = "GetData";
data = "";
ajaxCall(type, url, methodName, data)
}
function ajaxCall(type, url, methodName, data) {
var fullUrl = url + "\\" + methodName;
if (navigator.appName == 'Netscape')
fullUrl = url + '/' + methodName;
var d = "{}";
if (data != "") d = '{"data":"' + data + '"}';
else d = "{}";
$.ajax({
type: type,
url: fullUrl,
data: d ,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
processData: 'true',
success: function (msg) { alert('OK'); },
error: function (a, b, c) { alert('error' + a + b + c + ">"); }
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h1>
JSONP Service Client Page</h1>
</form>
<input type="button" value="click me" onclick="WCFJSON()" />
</body>
</html>
i searched alot but couldent find and solve my problem.
i need to call services in my project , but when i cant working with this simple service , i realy diapointed myself. please someone help me.