我在运行时创建了托管Web服务的网站,引发了运行时错误
在“尝试”服务实施的合同列表中找不到合同名称“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>
答案 0 :(得分:2)
在web.config中将合同属性从“ITry”更新为“test1.ITry”。
<services>
<service name="test1.Try">
<endpoint address="http://localhost:8732/Try" binding="webHttpBinding" contract="test1.ITry"/>
</service>
</services>