2013-12-16 1 views
2

나는 편안한 서비스를 만들고 웹 페이지에서이 서비스를 호출하려고합니다. 는하지만 난 오류 코드를 405jquery의 Restful Service call에 대한 상태 코드 405

같은 REST 서비스 호출을 얻고 아래

이 wevservice의 세부 사항 및 JQuery와 통화

웹 서비스 API를이다 비누 UI와 함께 잘 작동

[OperationContract] ListMethodWithCustomerArray (List dataStrings) [WebInvoke (Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "PostMethodWithCustomerArray")] 목록 PostMethodWithCustomerArray

Webservice를 코드

public List<CustomerWithArray> PostMethodWithCustomerArray(List<CustomerWithArray> dataStrings) 
    { 
     return dataStrings; 
    } 

아약스 호출

var UrlPostMethodWithCustomerArray = "http://localhost:29745/RESTfulService.svc/PostMethodWithCustomerArray"; 

    var customerWithArray = [{ "Name": "Dipak Godbole", "Age": "27", "HumanType": "1", "strArray": ["11", "22"] }, 
    { "Name": "Madan Chapa", "Age": "19", "HumanType": "3", "strArray": ["111", "222"] }, 
    { "Name": "Raju Rohida", "Age": "55", "HumanType": "2", "strArray": ["1111", "2222"] }]; 

$(document).ready(function() { 
    $.ajax({ 
     cache: false, 
     type: "POST", //GET or POST or PUT or DELETE verb 
     url: UrlPostMethodWithparam, // Location of the service 
     data: JSON.stringify(customerWithArray), 
     dataType: "json", //Expected data format from server 
     contentType: "application/json; charset=utf-8", 
     success: function (msg) {//On Successfull service call 

      $.each(msg, function (index, item) { 
       alert(item.Name + item.HumanType); 
      }); 
      //alert(msg); 
     }, 
     error: ServiceFailed// When Service call fails 
    }); 
}); 

웹 구성 섹션

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

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5"/> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="TrialRESTService.RESTfulService" behaviorConfiguration="svcbehaviour"> 
     <endpoint address="" 
        binding="webHttpBinding" 
        contract="TrialRESTService.IRESTfulService"/> 
     </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="svcbehaviour"> 
      <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true"/> 
    <httpProtocol> 
     <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     <add name="Access-Control-Allow-Methods" value="POST,GET"/> 
     </customHeaders> 
    </httpProtocol> 
    </system.webServer> 



</configuration> 

이 도움말은 무엇입니까?

오류 사용하여 Google Crome 스 개발자 도구

OPTIONS 
    http://localhost:29745/RESTfulService.svc/PostMethodWithCustomerArray 
    405 (Method Not Allowed) jquery-1.8.2.min.js:19 

XMLHttpRequest cannot load  http://localhost:29745/RESTfulService.svc/PostMethodWithCustomerArray. Invalid HTTP status code 405 Default.aspx:1 
+0

도움을 주 었는가? – Saranya

답변

0

이 데이터 페이로드에 대한 잘못된 (유효하지 JSON) 대신

data: JSON.stringify("Dipak Godbole") 

당신은해야

data: JSON.stringify("{name: Dipak Godbole}") 

이 SO 게시물을 확인해야합니다. Post data to RESTful Invalid HTTP status code 405

0

아래 예제와 같이 webHttpBinding endpoint의 동작 구성에 <enableWebScript/>을 추가해보십시오.

<system.serviceModel> 
<services> 
    <service name="WCF.TestWCF" behaviorConfiguration="TestWCFBehaviour"> 
    <endpoint address="" binding="webHttpBinding" contract="WCF.ITestWCF" behaviorConfiguration="TestWCFEndPointBehaviour"></endpoint>  

    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="TestWCFBehaviour"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="TestWCFEndPointBehaviour"> 
     <enableWebScript/> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

+1

나는 enablewebscript를 추가 한 후 uritemplate를 사용했습니다. "UriTemplate을 사용하는 끝점은 'System.ServiceModel.Description.WebScriptEnablingBehavior'와 함께 사용할 수 없습니다." – Radhi

+0

uri 템플릿을 제거 할 수 있습니까? 그 경우에 – Saranya

+0

은 "404"를 얻습니다 : ( – Radhi

관련 문제