0
jQuery에서 WCF 메서드를 호출하는 방법을 다루는 게시물이 12 개 있습니다. 작동하지 못합니다. 나는이 구현jQuery에서 WCF 서비스를 호출 할 수 없습니다.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
가
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string GetData(int value);
}
간단한 WCF 서비스 응용 프로그램을 가지고 그리고 이것은
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="TestWebApp.Service1AspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="TestWebApp.Service1AspNetAjaxBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="jQueryToWCF.Service1">
<endpoint address=""
behaviorConfiguration="TestWebApp.Service1AspNetAjaxBehavior"
binding="webHttpBinding"
contract="jQueryToWCF.IService1" />
</service>
</services>
지금 내가 노력하고 내 서비스의 Web.config입니다 jQuery (html 페이지)에서 이것을 호출하는 방법
$(document).ready(function() {
var param = "{value: 'Hello World!'}";
$.ajax({
type: "GET",
url: "http://localhost:5555/Service1.svc/GetData",
data: param,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert(result.d);
}
});
});
하지만 전화를 걸면 서비스를받을 수 없습니다. 나는 Fiddler에 의해 그것을 조사했다. 그러나 브라우저에 URL을 넣을 때 응답을 얻을 수 있습니다. 아무도 내가 이것을 알아낼 수 있도록 도와 줄 수 있습니까?
또한,이 CodeProject의 기사는 실제로 작동하도록 관리했습니다 크로스 도메인 호출의 첫 번째 예이다. 위의 프로젝트와 통합 할 때 jsonp와의 크로스 도메인을 수행하는 업데이트 된 파일을 게시 할 예정입니다. http://www.codeproject.com/Articles/223572/Calling-Cross-Domain-WCF-service-using-Jquery- Java – theo
http://submissiv.com/share/playground.wcf.service_jsonp.zip - 이것은 교차 도메인에서 작동합니다. – theo