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



考虑一下:

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

我已经在我的IIS中定向了一个新的应用程序到工件,并且能够冲浪到文件。但是,当我尝试调用CoolAction时(通过浏览到http://localhost/MySvc/CreditCardExtractor.svc/CoolAction)

由于EndpointDispatcher的ContractFilter不匹配,带有"Action"的消息无法在接收端处理。这可能是由于合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的契约和相同的绑定(包括安全要求,例如Message、Transport、None)。

这是我的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>

您已经定义了您的端点行为-但是您还没有应用到服务端点-尝试更新您的配置为:

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

最新更新