2013-09-05 1 views
1

나의 요구 사항은 Jquery Ajax와 서비스 참조를 추가하여 간단한 WCF 서비스를 호출 할 수 있어야한다.Jquery와 Service Reference 모두에서 WCF 서비스 호출하기

이 작업은 asmx 서비스에서 쉽게 수행 할 수 있습니다.이 단순한 작업이 매우 어렵고 복잡해 졌을 때 WCF가 "더 좋고 더 강력 할"수있는 방법을보기 위해 정말 고심하고 있습니다. 내가 ServiceReference가 아닌 JQuery와 또는 그 반대를 호출 할 수있는 http://www.codeproject.com/Articles/540169/CallingplusWCFplusServicespluswithplusjQuery-e2-80 http://blog.thomaslebrun.net/2011/11/jquery-calling-a-wcf-service-from-jquery/#.UihK6saa5No

http://www.codeproject.com/Articles/132809/Calling-WCF-Services-using-jQuery 그러나 나는 항상 해결책을 결국 : 같은

내가 따랐다 다양한 자습서. 다음과 같은 간단한 서비스에 대한

, 사람이 나를 제공하시기 바랍니다 수 있습니다

  • 필요한 모든 바인딩/엔드 포인트/행동/등으로
  • 의 Web.config ServiceModel은 서비스 섹션과 서비스 및 인터페이스를 장식하는 속성

.Jquery (ajax)에서 WCF 서비스를 호출하고 .net 프로젝트에서 서비스 참조를 추가하면 편리합니까?

아니면 그냥 오래된 좋은 (그러나 분명히 덜 강력한) amsx로 돌아 가야합니까?

+0

을> –

답변

0

자바 스크립트에서 호출되는 WCF 서비스에 webhttpbinding을 사용했습니다.

의 Web.config :

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

서비스 : 서비스 참조 사용

namespace WCF{ 
[ServiceContract(Namespace = "Saranya")] 
public interface ITestWCF 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml)] 
    String HelloWorld(); 
}} 



namespace WCF{ 
[AspNetCompatibilityRequirements(RequirementsMode = 
    AspNetCompatibilityRequirementsMode.Allowed)] 
public class TestWCF:ITestWCF 
{ 
    public String HelloWorld() 
    {         
     return "Hello World!!"; 
    }  
} 



    Using Jquery: 


$.post("http://localhost:26850/Service1.svc/HelloWorld?", null, fnsuccesscallback, "xml"); 
function fnsuccesscallback(data) { 
        alert(data.xml);   

    } 

: JQuery와에서 호출 할 때 당신이 얻을 오류가 무엇

obj = new Saranya.ITestWCF(); 
        obj.HelloWorld(fnsuccesscallback); 
function fnsuccesscallback(data) { 
        alert(data.xml); 

       }