AMH
AMH

Reputation: 6451

cannot host WCF service

I created website to host web service when run it raise runtime error

The contract name 'ITry' could not be found in the list of contracts implemented by the service 'Try'.

My WCF service interface and class look like that

namespace test1
{
   [ServiceContract]
   public interface ITry
   {
        [OperationContract]
        [WebInvoke(Method = "GET",
         ResponseFormat = WebMessageFormat.Json,
         UriTemplate = "data/{username}/{password}")]
        string Login(string username, string password);
    }
}

Service implementation:

namespace test1
{
    public class Try : ITry
    {
        public string Login(string username, string password)
        {
            using (var instance = new FacultySystemEntities1())
            {
                var user = instance.Users.Where(u => u.UserName == username && u.UserPassword == password).FirstOrDefault();

                if (user != null)
                    return "true";
                else
                    return "false";
            }
        }
    }
}

and the web site , web.config is look like

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="test1.Try">
        <endpoint address="http://localhost:8732/Try" binding="webHttpBinding" contract="ITry"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Upvotes: 0

Views: 886

Answers (1)

Martin4ndersen
Martin4ndersen

Reputation: 2876

Update the contract attribute from "ITry" to "test1.ITry" in the web.config.

<services> 
  <service name="test1.Try"> 
    <endpoint address="http://localhost:8732/Try" binding="webHttpBinding" contract="test1.ITry"/> 
  </service> 
</services> 

Upvotes: 2

Related Questions