0

我创建了网站以在运行时托管 Web 服务引发运行时错误

在服务“Try”实施的合同列表中找不到合同名称“ITry”。

我的 WCF 服务接口和类看起来像这样

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

服务实现:

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";
            }
        }
    }
}

和网站,web.config 看起来像

<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>
4

1 回答 1

2

将 web.config 中的合同属性从“ITry”更新为“test1.ITry”。

<services> 
  <service name="test1.Try"> 
    <endpoint address="http://localhost:8732/Try" binding="webHttpBinding" contract="test1.ITry"/> 
  </service> 
</services> 
于 2012-05-20T06:58:03.537 回答