【问题标题】:Can't surf to WCF REST service from browser无法从浏览器浏览到 WCF REST 服务
【发布时间】:2015-10-24 03:00:42
【问题描述】:

考虑一下:

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

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

我明白了

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

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

【问题讨论】:

    标签: wcf rest wcf-rest


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-14
      相关资源
      最近更新 更多