Serge Profafilecebook
Serge Profafilecebook

Reputation: 1205

WCF method not called

I'm trying to create a very simple WCF service inside my already existing ASP.Net application.
The WCF is be hosted inside the application and I guess, if done properly it doesn't need a binding address (it's already at /Pages/Login.svc) to be set in web.config.

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

+

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace CRM.Pages
{
    [ServiceContract]
    public interface ILogin
    {
        [OperationContract]
        JSONLogin Log();
    }
}

+

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;

namespace CRM.Pages
{
    [DataContract]
    public class JSONLogin
    {
        [DataMember]
        public string ErrorMsg
        {
            get;
            set;
        }
    }

    public class Login : ILogin
    {
        [WebGet(
            ResponseFormat = WebMessageFormat.Json
            , UriTemplate = "Log"
        )]
        public JSONLogin Log()
        {
            return new JSONLogin()
            {
                ErrorMsg = "test"
            };
        }
    }
}

When I go to /Pages/Login.svc I get the description page, but then when I get to "/Pages/Login.svc/Log" nothing happens, the code doesn't run. I guess there's a last step I might have forget.

EDIT:

Solution

<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service name="CRM.Pages.Login">
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" contract="CRM.Pages.ILogin"></endpoint>
  </service>
</services>

Upvotes: 0

Views: 259

Answers (1)

Coder1409
Coder1409

Reputation: 498

It is a REST based service so some configuration is needed

add this to your Web.config

<services>

  <service name="EnterName" behaviorConfiguration="RestService" >
   <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" contract="IContract"></endpoint>
  </service>
</services>

and under behaviors add an endpoint behavior to enable web http

  <endpointBehaviors>
  <behavior name="web">
    <webHttp/>
  </behavior>
</endpointBehaviors>

Change your webget attribute

 [WebGet(
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.WrappedResponse,
        UriTemplate = "/log")]

Upvotes: 1

Related Questions