我正在努力解决WCF服务配置的问题。我有以下配置:
<behaviors>
<serviceBehaviors>
<behavior name="SampleWebBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false"/>它工作得很好,我可以用WcfTestClient.exe来尝试这些方法,并得到正确的响应。但是我需要绑定为webHttpBinding,这样我就可以在浏览器中看到结果并创建JSON请求和响应。但是,当我将绑定更改为webHttpBinding,时,它会引发一个错误:
由于ContractFilter在EndpointDispatcher上不匹配,无法在接收端处理带有动作的消息“”。这可能是因为契约不匹配(发送方和接收方之间的操作不匹配),或者是发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的约束力(包括安全要求,例如消息、传输、无)。
寻求任何帮助。
发布于 2012-09-21 14:06:47
要做到这一点,您需要在配置中做一些事情。
1)将另一个端点添加到您的服务中,您可以看到下面有basicHttp和webHttp
<system.serviceModel>
<services>
<service name="<serivceclass>" behaviorConfiguration="DefaultBehavior">
<endpoint binding="basicHttpBinding" contract="<serviceinterface>" bindingConfiguration="soapBinding"/>
<endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="<serviceinterface>" bindingConfiguration="jsonBinding"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</system.serviceModel>2)添加绑定配置(同样,您将看到web和basichttp)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soapBinding" maxBufferPoolSize="9000000" maxBufferSize="9000000" maxReceivedMessageSize="9000000">
<readerQuotas maxArrayLength="9000000" maxBytesPerRead="9000000" maxDepth="9000000" maxNameTableCharCount="9000000" maxStringContentLength="9000000"/>
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="jsonBinding">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>3)设置您的行为-注意这些名称以及它们与步骤1中列出的端点之间的关联
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="9000000" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>虽然我启用和配置的一些内容是可选的,但这允许您以两种方式访问服务,一种是使用web和json的方式,另一种是在不使用javascript时使用内置到visual studio中的工具,等等。
Note1:当您使用json部分时,端点是http://myhost.com/myservice.svc/json/MyMethodName,您可以通过修改适当的服务端点线上的" address“属性来更改它(参见基本地址是空的,webHttp是'json')。
发布于 2012-09-21 14:11:30
导致此错误的一种可能性是:当您更改配置时,您在服务器或客户端上进行了更改,但两者都没有更改。服务器和客户端上的配置必须匹配。
https://stackoverflow.com/questions/12531970
复制相似问题