我在C#中有三个项目的解决方案:
我在CareLife.ServiceLayer中添加了项目CareLife.BusinessLayer的.dll(找到obj文件夹),因为需要在项目ServiceLayer中访问BusinessLayer的方法。
namespace CareLife.BusinessLayer.Operations
{
public class SpecialityServices
{
void GetArea() { }
}
}
和....
namespace CareLife.ServiceLayer
{
[ServiceContract]
public class SpecialityOperations
{
[OperationContract]
[WebInvoke(UriTemplate="Area", Method="GET")]
ICollection<Area> GetArea()
{
try
{
SpecialityServices specialityServices = new SpecialityServices();
}
catch (Exception)
{
throw;
}
return null;
}
}
}
问题是:为什么当我在SpecialityServices类的ServiceLayer中转到定义时,我总是重定向到元数据类?
答案 0 :(得分:0)
我在这里定义的资源是Area。您是否在http:// <serviceRoot
&gt; / Area?
另外,如果您正在构建休息服务,为什么不使用WebAPI?
答案 1 :(得分:0)
您是否尝试将其作为项目参考而不是obj文件夹中的dll添加?
答案 2 :(得分:0)
您应该显式声明webHttp端点。以下是示例system.serviceModel
配置部分:
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint address="basic" binding="basicHttpBinding" contract="WcfService1.IService1" />
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="web"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
为了澄清,我要将endpointBehaviors
部分和webHttp endpoint
添加到服务部分