本文介绍了无法在接收方处理,因为EndpointDispatcher的AddressFilter不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ajax启用WCF,当我在网络浏览器中打开网址,我得到这个错误。

I am using ajax enabled WCF, when i open the url in web browser i am getting this error.

MobileService代码如下

MobileService code is given below

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]
    }
}

AND
服务web.config文件是

ANDService web.config file is

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MobileService.webHttpBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="MobileService.MobileService">
        <endpoint binding="webHttpBinding" contract="MobileService.MobileService" />
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

可以帮助我犯错误。

推荐答案

您的端点需要一个< webHttp /> 端点行为。

You need a <webHttp/> endpoint behavior for your endpoint. If you add that (see below) it should work.

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

这篇关于无法在接收方处理,因为EndpointDispatcher的AddressFilter不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:59