如何创建F#WCF客户端?我一直收到app.config错误

Eri*_*ick 6 wcf f#

我一直在用F#创建自托管应用服务器.我已经启动并运行了应用服务器,我可以使用C#客户端进行连接,但是使用F#可以更好地完成我想做的一些事情.问题是我似乎无法使F#客户端正常工作.我找到了一些例子,但我似乎无法让它们中的任何一个起作用.最有希望的是这里.在这个例子后,我想出了以下代码:

let address= new EndpointAddress("net.tcp://192.168.101.100:2009/PrevisionService/tcp")
let factory = new ChannelFactory<IPrevisionAppServer>("NetTcpBinding_IPrevisionAppServer", address)
let channel = factory.CreateChannel()//address)
let GetDataObject (sql) = channel.GetDataObject(sql)
factory.Close()
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

找不到名为"NetTcpBinding_IPrevisionAppServer"的端点元素,并在ServiceModel客户端配置部分中收缩"PrevisionAppServer.Main + IPrevisionAppServer".这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素.

我有一个app.config文件,它在C#中工作得很好:

<?xml version="1.0" encoding="utf-8"?>
<!--Client Config-->
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IPrevisionAppServer" closeTimeout="00:01:00"
          openTimeout="00:20:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
          hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647"
          maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647"
            maxStringContentLength="2147483647"
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"
            maxNameTableCharCount="2147483647" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://192.168.101.100:2009/PrevisionService/tcp" behaviorConfiguration="ServiceViewEventBehavior"
          binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IPrevisionAppServer"
          contract="*" name="NetTcpBinding_IPrevisionAppServer">
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceViewEventBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>`
Run Code Online (Sandbox Code Playgroud)

无论出于何种原因,它似乎忽略了app.config文件.有任何想法吗?是否有更好的代码来实现这一点?任何人将不胜感激!

更新:好的,我觉得很愚蠢,但我没注意到我在一个测试客户端运行它,它也有一个C#UI作为启动,因此app.config在C#项目中.那么,现在问题变成了,如何将C#app.config应用到F#项目(我需要这样)?这意味着,我真的不想将所有属性的获取和设置从应用程序设置编码为代码.想法?

Bri*_*ian 2

我不知道这contract="*"是什么(也许是 WCF 的一些新功能)。无论如何

'PrevisionAppServer.Main+IPrevisionAppServer' 
Run Code Online (Sandbox Code Playgroud)

诊断中的位,该类型在哪里定义?(F# 代码、C# 代码、参考 DLL,什么?)它看起来像一个嵌套类型,我想知道这是否也会影响事情......我只是在钓鱼。

(叹息,app.config 和诊断从来都不是 WCF 最强的属性。)