2012-12-21 2 views
1

asp.net에서 내 응용 프로그램의 백엔드를 작성하려고하는데 Ext에서 Ajax 요청 후 POST 응답을 반환 할 수없는 WCF 서비스를받을 수 없습니다. 대신 405 'Method not allowed'오류가 발생합니다..net WCF 서비스에서 응답 오류가 발생했습니다.

namespace RestService 
{ 
    public class RestServiceImpl : IRestServiceImpl 
    { 
     #region IRestServiceImpl Members 

     public string JSONData() 
     { 
      return "Your POST request"; 
     } 

     #endregion 
    } 
} 

및 서비스 코드 :

using System.ServiceModel; 
using System.ServiceModel.Web; 
using System.Web.Script.Services; 

namespace RestService 
{ 

    [ServiceContract] 
    public interface IRestServiceImpl 
    { 
     [OperationContract] 
     [ScriptMethod] 
     [WebInvoke(Method = "POST", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Bare, 
      UriTemplate = "export")] 
     string JSONData(); 
    } 
} 

그리고 마지막으로 설정 :

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour"> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web"> 
      <!-- 
       Upon deployment, the following identity element should be removed or replaced to reflect the 
       identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
       automatically. 
      --> 
     </endpoint> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 
이 내 인터페이스

Ext.Ajax.request({ 
    type: 'POST', 
    url: 'http://localhost:35798/RestServiceImpl.svc/export', 
    params: { 
     html  : {'array': document.body.innerHTML} 
    }, 
    success : function(response){ 
    console.log('RESPONSE !', response); 
     //me.onSuccess(response, callback, errback); 
    }, 
    failure : function(response){ 
     console.log('RESPONSE FAIL !', response); 
    } 
}); 

:

내 요청입니다
+2

첫 번째 추측 : 아약스 요청에서 "매개 변수"를 제거해야한다고 가정합니다. 메서드는 아무 것도 필요하지 않으므로 말입니다. – Pete

답변

1

이것은 도메인 간 문제 일 수 있습니다. 예를 들어 서비스가 http://localhost:35798이고 AJAX 요청을하는 웹 페이지가 http://localhost:80 인 경우 브라우저에 따라 다른 도메인으로 간주됩니다 (포트 번호 만 다르더라도). 이 경우 일부 브라우저는 CORS 요청을 발행하고 서비스가이를 처리하지 않으면 405를 반환합니다. 그런 다음 (1) 도메인 간 요청을 피하거나, (2) CORS를 구현하거나 (브라우저를 지원하지 않습니다. (3) JSONP를 사용하십시오.

관련 문제