无法从浏览器浏览WCF REST服务

时间:2015-08-01 14:35:53

标签: wcf rest wcf-rest

考虑一下:

[ServiceContract]
public interface ICreditCardExtractor
{       
        [OperationContract]
        [WebGet]
        string CoolAction();
}

我已将IIS中的新应用程序指向工件,并能够浏览文件。 但是,当我尝试调用CoolAction(通过浏览到http://localhost/MySvc/CreditCardExtractor.svc/CoolAction

我得到了

  

带有操作的消息''由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。

这是我的web.config

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.5"/>
        <httpRuntime targetFramework="4.5"/>
         <!--pages controlRenderingCompatibilityVersion="4.0"/-->
    </system.web>
    <system.serviceModel>
        <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>
        <!--added service behaviour configuration-->
        <services>
            <service name="WcfService1.CreditCardExtractor">
                <endpoint 
                    address="" 
                    binding="webHttpBinding"  
                    contract="WcfService1.ICreditCardExtractor" />
            </service>
        </services>
        <serviceHostingEnvironment  
                aspNetCompatibilityEnabled="true" 
                multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    ....
</configuration>

1 个答案:

答案 0 :(得分:0)

已定义您的终端行为 - 但您尚未应用于服务终端 - 尝试将您的配置更新为:

<services>
    <service name="WcfService1.CreditCardExtractor">
        <endpoint 
            address="" 
            behaviorConfiguration="web"  -- add this line here!!
            binding="webHttpBinding"  
            contract="WcfService1.ICreditCardExtractor" />
    </service>
</services>