Click here to Skip to main content
13,795,749 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
{
   [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.
Posted 28-May-12 19:02pm
Comments
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
Web06 | 2.8.181207.3 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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