是的,它是可行的——至少在调试模式下是这样。至少可以说,我有点挣扎。我希望其他人可以从中受益。
要使其与 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/