我是 WCF 的新手,正在测试一个简单的示例,但我被困了太久。我错过的错误或事情可能很愚蠢,但请帮助我。提前非常感谢。
这是我对问题的描述:
我正在测试启用了 json 的 WCF 服务,该服务在我的CalService.svc.cs
文件中通过以下代码实现:
namespace SharePoint.WebServices
{
[ServiceContract]
public interface ICalculators
{
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json
)]
float Weight(float width, float diameter, float size, float factor);
}
public class Calculators : ICalculators
{
public float Weight(float width, float diameter, float size, float factor)
{
return 10f;
}
}
}
我的CalService.svc
文件是这样的:
<%@
ServiceHost
Language="C#"
Debug="true"
Service="SharePoint.WebServices.Calculators"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
CodeBehind="CalService.svc.cs"
%>
我用 IE 测试了我的示例服务。我收到了no endpoint found
消息通知。因此,我认为问题来自我的 web.config 文件。这里是:
<system.serviceModel>
<services>
<service name="SharePoint.WebServices.Calculators">
<endpoint
address=""
behaviorConfiguration="JsonBehavior"
binding="webHttpBinding"
contract="SharePoint.WebServices.ICalculators" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我已经检查了那些回复了有关启用 json 的 wcf 的类似线程的人提出的所有观点,但仍然存在端点问题。请帮忙!