2014-04-15 109 views
1

Dart可以使用WCF服務嗎?如果是這樣,怎麼樣?從一個「Javascript < - > ASP.NET < - > WCF服務< - > SQL」web應用程序到一個帶有Dart前端的程序?Dart可以使用WCF服務嗎?

+0

這不是一個sql問題。這是一個wcf/dart問題 – gh9

+0

在網上搜索「dart consume web service」並嘗試一些庫,這些庫可以執行REST或SOAP調用。 – CodeCaster

回答

1

是的,它是可行的 - 至少在調試模式下。至少可以說,我掙扎了一下。我希望其他人能從中受益。

要使其與dart一起工作,您需要將dart項目放置在解決方案文件夾下的子文件夾中,並將(dart)文件包含在Visual Studio項目中。

陷阱: 我調用的函數是來自飛鏢視角的字符串,但.NET必須使用流。我希望有人能展示更好的解決方案。

所以我在我的ICalculationService中有這個。我希望有人能揭示爲什麼它是這樣一些輕:

  [OperationContract] 
      System.IO.Stream RunCalculation(System.IO.Stream calculation); 

鏢代碼很簡單(和程序員很欣賞簡潔)

  void runCalculation() { 
       String url = "http://localhost:5548/CalculationService.svc/RunCalculation"; 
       String data = "raw stuff to send to the service"; 
       Future<HttpRequest> request = HttpRequest.request(url, method: 'POST',sendData: data); 
       request.then((HttpRequest resp) { 
       DivElement div = querySelector("#someresult_div"); 
       div.text = resp.responseText; 
       }); 
      } 

這裏是工作的web配置(項目是一個WCF服務應用程序):

  <?xml version="1.0"?> 
      <configuration> 
       <appSettings/> 
       <system.web> 
       <compilation debug="true" targetFramework="4.0"/> 
       <httpRuntime/> 
       </system.web> 
       <system.serviceModel> 
       <behaviors> 
        <endpointBehaviors> 
        <behavior name="YourDefaultNamespace.CalculationService"> 
         <enableWebScript/> 
        </behavior> 
        </endpointBehaviors> 
        <serviceBehaviors> 
        <behavior name="debug"> 
         <serviceDebug includeExceptionDetailInFaults="true"/> 
         <serviceMetadata httpGetEnabled="true"/> 
        </behavior> 
        <behavior> 
         <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
         <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> 
       </behaviors> 
       <protocolMapping> 
        <add binding="basicHttpsBinding" scheme="https"/> 
       </protocolMapping> 
       <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
       <services> 
        <service name="YourDefaultNamespace.CalculationService" behaviorConfiguration="debug"> 
        <endpoint address="" behaviorConfiguration="YourDefaultNamespace.CalculationService" binding="webHttpBinding" contract="YourDefaultNamespace.ICalculationService"/> 
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/> 
        </service> 
       </services> 
       </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"/> 
       <staticContent> 
        <remove fileExtension=".dart"/> 
        <mimeMap fileExtension=".dart" mimeType="text/x.dart"/> 
       </staticContent> 
       </system.webServer> 
      </configuration> 

如果你想要做的東西,在純JavaScript,這可能有助於瞭解在不起眼的WCF/asp.net世界發生:http://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-without-asp-net-ajax/

相關問題