我有一个wcf restful服务启动并运行。如果我使用WebServiceHost启动Web服务,我可以发出没有问题的Get / Post。我尝试将wcf服务移动到我本地机顶盒上的IIS 7.5,我似乎无法实现它。
我一直在尝试从wcf服务中调用任何内容时出现以下错误:(http:// wp9dbytr1k1:8081 / service.svc / AnythingHereForGETorPUT)。我已经尝试过虚拟目录/设备,我也遇到了同样的问题。
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).
如果我直接调用svc文件(http:// wp9dbytr1k1:8081 / service.svc),它很开心并告诉我
“您已创建了一项服务。 要测试此服务,您需要创建一个客户端并使用它来调用该服务。您可以使用命令行中的svcutil.exe工具执行此操作,语法如下: svcutil.exe http://wp9dbytr1k1:8081/FUU/service.svc?wsdl“
来自Trace查看器的strack跟踪没有帮助:抱歉,必须添加一个链接,不允许发布图像。 (ImageLink)
这是我的web.config
<system.serviceModel>
<bindings>
<mexHttpsBinding>
<binding name="NewBinding0" />
</mexHttpsBinding>
<webHttpBinding>
<binding name="WebBinding">
<readerQuotas maxDepth="524288" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="StoredProcBehaviors" name="StoredProcService.DataRetreivalService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="WebBinding"
contract="StoredProcService.IDataRetreivalService">
<identity>
<dns value="locahost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="StoredProcService.IDataRetreivalService" />
<host>
<baseAddresses>
<add baseAddress="http://WP9DBYTR1K1:8081/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="StoredProcBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
由于显而易见的原因,这感觉就像IIS设置一样,因为它与WebServiceHost一起使用。我已经搜索了关于如何设置它的错误/教程,一切对我来说都很好。
有什么建议吗?
由于
答案 0 :(得分:5)
要在WCF中创建REST端点,除了使用WebHttpBinding之外,还需要在其上具有端点行为。
<system.serviceModel>
<services>
<service behaviorConfiguration="StoredProcBehaviors" name="StoredProcService.DataRetreivalService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="WebBinding" behaviorConfiguration="REST"
contract="StoredProcService.IDataRetreivalService">
<identity>
<dns value="locahost" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp/>
</behavior>
<endpointBehaviors>
</behaviors>
</system.serviceModel>
另一种选择是在.svc文件中使用WebServiceHostFactory,它与WebServiceHost类似。在这种情况下,您甚至不需要web.config中的system.serviceModel部分。
<% @ServiceHost Service="StoredProcService.DataRetreivalService" Factory="System.ServiceModel.Activation.WebServiceHostFactory" Language="C#" debug="true" %>