【发布时间】:2013-01-02 23:51:27
【问题描述】:
我正在使用启用 ajax 的 WCF,当我在 Web 浏览器中打开 url 时出现此错误。
接收方无法处理带有 Action 'http://localhost:22219/MobileService.svc/GetProductCategories' 的消息,因为 EndpointDispatcher 的 ContractFilter 不匹配。这可能是 因为合同不匹配(不匹配的操作之间 发送方和接收方)或发送方之间的绑定/安全不匹配 和接收器。检查发送方和接收方是否相同 合同和相同的约束力(包括安全要求,例如 消息,传输,无)。
MobileService 代码如下
namespace MobileService
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MobileService
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetProductCategories")]
public List<String> GetProductCategories()
{
List<String> categoryList = new List<string>();
categoryList.AddRange(new String[] { "Electronics", "Housewares", "Computers", "Software", "Music" });
return categoryList;
}
// Add more operations here and mark them with [OperationContract]
}
}
与 服务 web.config 文件是
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.MobileServiceAspNetAjaxBehavior">
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileService.MobileService">
<endpoint address="" behaviorConfiguration="MobileService.MobileServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="MobileService.MobileService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
谁能帮我解决我犯的错误。
【问题讨论】:
-
这很令人困惑,因为答案已被编辑到问题中。原来
<webHttp />不存在。 -
@DavidSherret 借调。
-
我要回滚了。
标签: asp.net wcf c#-4.0 asp.net-ajax wcf-binding