asp.net - Dart可以使用WCF服务吗?

标签 asp.net wcf dart

Dart可以使用WCF服务吗?如果是这样,怎么办?

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

最佳答案

是的,它可行-至少在 Debug模式下。至少可以说,我对此有点挣扎。我希望其他人可以从中受益。

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

陷阱:
从Darts的 Angular 来看,我调用的函数是字符串,但是.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;
              });
            }

这是一个有效的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/

关于asp.net - Dart可以使用WCF服务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23090521/

相关文章:

asp.net - sql server 数据库设计

asp.net - 如何修复 web.config 中重写部分的无效配置错误

wcf - MVVM 中使用服务的目的

dart - 加快酒吧进入容器的技巧?

flutter - Dart 将 Map<dynamic, dynamic> 转换为 Map<String, List<String>>

asp.net - 获取当前的 ASP.NET 机器 key

asp.net - 如何取消上传

通过 SSL 进行 SOAP 纯文本密码身份验证的 WCF 配置

wcf - 404 BadRequest使用IIS主机 header 通过外部IP公开WCF服务

flutter - 在 flutter 中单击容器内部