无法从浏览器浏览到 WCF REST 服务
Can't surf to WCF REST service from browser
考虑一下:
[ServiceContract]
public interface ICreditCardExtractor
{
[OperationContract]
[WebGet]
string CoolAction();
}
我已将我的 IIS 中的一个新应用程序定向到工件,并且能够浏览到文件。
但是,当我尝试调用 CoolAction
(通过浏览到 http://localhost/MySvc/CreditCardExtractor.svc/CoolAction
)
我明白了
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. 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>
考虑一下:
[ServiceContract]
public interface ICreditCardExtractor
{
[OperationContract]
[WebGet]
string CoolAction();
}
我已将我的 IIS 中的一个新应用程序定向到工件,并且能够浏览到文件。
但是,当我尝试调用 CoolAction
(通过浏览到 http://localhost/MySvc/CreditCardExtractor.svc/CoolAction
)
我明白了
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. 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>