【问题标题】:Can Dart consume WCF services?Dart 可以消费 WCF 服务吗?
【发布时间】:2014-05-30 05:01:05
【问题描述】:

Dart 可以使用 WCF 服务吗?如果有,怎么做?

更广泛地说,如何从“Javascript ASP.NET WCF 服务 SQL” Web 应用程序转变为具有 Dart 前端的应用程序?

【问题讨论】:

  • 这不是一个 sql 问题。这是一个 wcf/dart 问题
  • 在网络上搜索“dart 消费网络服务”并尝试使用一些库来执行 REST 或 SOAP 调用。

标签: asp.net wcf dart


【解决方案1】:

是的,它是可行的——至少在调试模式下是这样。至少可以说,我有点挣扎。我希望其他人可以从中受益。

要使其与 dart 一起使用,您需要将 dart 项目放在解决方案文件夹下的子文件夹中,并将 (dart) 文件包含在 Visual Studio 项目中。

问题: 从 Darts 的角度来看,我调用的函数是字符串,但 .NET 必须使用流。我希望有人能提出更好的解决方案。

所以我的 ICalculationService 中有这个。我希望有人可以阐明为什么必须这样:

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

dart 代码很简单(程序员也很欣赏这种简单性)

            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;
              });
            }

这是一个有效的网络配置(项目是一个 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/

【讨论】:

  • 任何想法如何处理服务器端所需的客户端证书?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-30
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多