找不到WCF json端点

时间:2013-09-02 01:46:30

标签: json wcf endpoint

我是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所做的所有观点,但仍然存在端点问题。请帮忙!

0 个答案:

没有答案
相关问题