如何在WCF中使用UDP托管服务?

时间:2016-12-19 07:42:20

标签: c# wcf udp wcf-binding

我正在尝试使用WCF中的UDP托管服务,但我无法从该服务生成代理。我需要在局域网上托管服务。任何人都可以为在WCF中使用UDP的服务器和客户端提供示例吗?

这是我的app.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>

    <extensions>
      <bindingElementExtensions>
        <add name="udp_Transport" type="Microsoft.ServiceModel.Samples.UdpTransportElement, UdpTransport" />
      </bindingElementExtensions>
    </extensions>

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          <serviceMetadata httpGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <udpBinding>
        <binding name="UDPBinding" openTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000" sendTimeout="24.20:31:23.6470000" maxBufferPoolSize="10000000" maxReceivedMessageSize="10000000">
          <readerQuotas maxDepth="10000000" maxStringContentLength="10000000" maxArrayLength="10000000" maxBytesPerRead="10000000" maxNameTableCharCount="10000000"/>         
        </binding>
      </udpBinding>
    </bindings>
    <services>
      <service name="UDP_Server.Service1">
        <endpoint address="soap.udp://localhost:40000/Service1/" binding="udpBinding" bindingConfiguration="UDPBinding" contract="UDP_Server.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>


        <host>
          <baseAddresses>
            <add baseAddress="soap.udp://localhost:40000/Service1/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

1 个答案:

答案 0 :(得分:0)

检查以下链接: https://www.codeproject.com/Articles/757349/Multicasting-using-UdpBinding-in-WCF

它还有一个代码示例。