이 문제점이있는 너트입니다. 나는 2 개의 프로젝트가있는 솔루션을 가지고 있는데, 그 중 하나는 jquery ajax 호출을 사용하는 평범한 구식 html과 다른 하나는 WCF 서비스입니다. html 페이지는 json 문자열을 가져 와서 표시 목적으로 사용하기 위해 WCF 서비스에 대한 ajax 호출을 발행합니다.WCF 오류 : 405 메서드가 허용되지 않습니다.
이제는 디버그 모드에서 실행될 때마다 html 페이지와 WCF가 서로 다른 포트로 시작됩니다. 그리고 이것은 테스트를 수행 할 때 (즉, 파이어 폭스에서 호출 유형 = OPTIONS와 함께 405 메소드가 허용되지 않는 오류가 발생하는) 크로스 발생 문제를 발생시킵니다. 내 아약스 스크립트에서 호출 메소드를 세 번 확인하면 WCF 서비스는 동일합니다 (GET).
google을 검색했지만 확장 프로그램을 설치하거나 IIS에서 일부 구성을 수행해야한다는 것을 알았습니다. IIS에서 내가 수행하는 작업이 간단하기 때문에 성가신 것으로 나타났습니다. 하나의 예에 따라, 내 Web.config의에서 다음과 같은 구성에 추가 싶지만 그것은 작동하지 않았다
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileService.SimpleMemberInfo" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileService.IMemberInfo" bindingConfiguration="crossDomain" behaviorConfiguration="MobileService.webHttpBehavior">
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
어떤 생각이 성가신 문제를 제거 할 수 있습니다 중 하나를?
편집 : 그냥 내가 WCF 코드에 추가 VS 스튜디오 2012
와 함께 제공 IIS Express를 사용하여 디버그 및 업데이트의 Web.config를하고 있는데, 추가
[ServiceContract]
public interface IMemberInfo
{
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json
)]
[OperationContract]
string GetMemberInfoById();
// TODO: Add your service operations here
}
내 스크립트 :
$(document).ready(function() {
$.ajax("http://localhost:32972/SimpleMemberInfo.svc/GetMemberInfoById", {
cache: false,
beforeSend: function (xhr) {
$.mobile.showPageLoadingMsg();
},
complete: function() {
$.mobile.hidePageLoadingMsg();
},
contentType: 'application/json',
dataType: 'json',
type: 'GET',
error: function() {
alert('Something awful happened');
},
success: function (data) {
var s = "";
s += "<li>" + data + "</li>";
$("#myList").html(s);
}
});
});
의
WebInvoke(Method = "POST")
이 링크는 http://stackoverflow.com/questions/2202500/wcf-service-405-method-not-allowed-exception – Mihai감사합니다 도움이 될 수 있습니다. 시도했지만 작동하지 않았습니다. – ipohfly
ops ok ...하지만 답변이 없으면 가장 가까운 것을 골라야합니까? – ipohfly