gpt4 book ai didi

asp.net - 由于 EndpointDispatcher 处的 AddressFilter 不匹配,无法在接收方处理

转载 作者:行者123 更新时间:2023-12-05 01:10:10 25 4
gpt4 key购买 nike

我正在使用启用 ajax 的 WCF,当我在网络浏览器中打开 url 时,我收到此错误。

The message with Action 'http://localhost:22219/MobileService.svc/GetProductCategories' 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).



移动服务代码如下
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/>端点的端点行为。如果您添加它(见下文),它应该可以工作。

  <endpointBehaviors>
<behavior name="MobileService.MobileServiceAspNetAjaxBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>

关于asp.net - 由于 EndpointDispatcher 处的 AddressFilter 不匹配,无法在接收方处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14412996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com