2013-01-19 74 views
4

我使用ajax啓用WCF,當我打開網址在網頁瀏覽器中,我得到這個錯誤。無法在接收器處理,由於在EndpointDispatcher AddressFilter不匹配

與動作「http://localhost:22219/MobileService.svc/GetProductCategories」消息不能在接收器進行處理,由於 在EndpointDispatcher一個ContractFilter失配。這可能是 ,因爲合同不匹配( 發件人與收件人之間的不匹配操作)或發件人 與收件人之間的綁定/安全不匹配。檢查發送方和接收方是否具有相同的 合同和相同的綁定(包括安全要求,例如 消息,傳輸,無)。下面

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文件

MobileService代碼給出是

<?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> 

任何一個可以幫助我在哪兒出錯了。

+1

這是令人困惑的,因爲答案被編輯到問題中。最初''不在那裏。 –

+0

@DavidSherret借調。 – Dragomok

+0

我要回滾它。 –

回答

14

您需要端點的<webHttp/>端點行爲。如果你添加(見下文)它應該工作。

<endpointBehaviors> 
    <behavior name="MobileService.MobileServiceAspNetAjaxBehavior"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
相關問題