Click here to Skip to main content
13,901,425 members
Rate this:
Please Sign up or sign in to vote.
See more:
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
    public interface IService1

        [WebInvoke(UriTemplate = "GetData",
                   Method = "Post",
                   ResponseFormat = WebMessageFormat.Json,
                   BodyStyle = WebMessageBodyStyle.Wrapped)]
        string GetData();



and this is my web.config :
    <compilation debug="true" targetFramework="4.0"/>
          <add name="CacheFor10Seconds" duration="10" varyByParam="none"/>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
        <behavior name="webHttpBehavior">
          <webHttp helpEnabled="true"/>
          <serviceMetadata httpGetEnabled="true"/>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
      <service name="MYWcfService.Service1">
        <endpoint address="" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="MYWcfService.IService1"/>
    <modules runAllManagedModulesForAllRequests="true"/>

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">
    <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 = "{}";
                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 + ">"); }

<form id="form1" runat="server">

        JSONP Service Client Page</h1>

<input type="button" value="click me" onclick="WCFJSON()" />


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.
Moonaly 29-May-12 1:02am
i mean by "IIS manager" , "WCF test client". i correct my sentence :
"when i run the service project in .net, WCF test client will run but because it is the webhttpbinding , it cant show my service."
Jim Jos 29-May-12 2:21am
Have tested it with basichttpbinding first? Please use basichttpbinding and see whether its working.. then we can be sure its only due to webhttpbinding..

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190306.1 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100