且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WCF- WPF应用

更新时间:2022-11-03 16:19:20

您的客户端必须在Web.config或App.config中包含相同的代码:

Your client must contain a same code in your Web.config or App.config:

<system.servicemodel>
    <bindings>
      <basichttpbinding>
        <binding name="basicHttpEndPointConfiguration" closetimeout="00:01:00">
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false"                   hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384">
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientcredentialtype="None" proxycredentialtype="None">
              realm="" />
            <message clientcredentialtype="UserName" algorithmsuite="Default" />
          </transport></security>
        </readerquotas></binding>
      </basichttpbinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/YourService.svc">
        binding="basicHttpBinding" bindingConfiguration="basicHttpEndPointConfiguration"
        contract="WCF.IYourService" name="basicHttpEndPointConfiguration" />
    </endpoint></client>
  </system.servicemodel>


//wcf-wpf客户端-宿主项目正常运行,但是当我将此项目导入////到我自己的小项目中时,客户端停止工作并给出异常. 无法在ServiceModel客户端配置部分中找到引用合同" SVC.IChat"的默认终结点元素.这可能是因为没有为您的应用程序找到配置文件,或者是因为在客户元素."

///这是我的app.config文件的样子:


// wcf-wpf client-host project run properly but when i imported this project //into my own small project then client stopped working and give exception.
" Could not find default endpoint element that references contract ''SVC.IChat'' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. "

/// this how my app.config file is:


 <configuration>
    <system.servicemodel>
        <bindings>
            <nettcpbinding>
                <binding name="NetTcpBinding_IChat" closetimeout="00:01:00" opentimeout="00:01:00">
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                    transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="67108864" maxBufferSize="67108864" maxConnections="100"
                    maxReceivedMessageSize="67108864">
                    <readerquotas maxdepth="32" maxstringcontentlength="67108864" maxarraylength="67108864">
                        maxBytesPerRead="67108864" maxNameTableCharCount="16384" />
                    <reliablesession ordered="true" inactivitytimeout="20:00:10">
                        enabled="true" />
                    <security mode="None">
                        <transport clientcredentialtype="Windows" protectionlevel="EncryptAndSign" />
                        <message clientcredentialtype="Windows" />
                    </security>
                </reliablesession></readerquotas></binding>
            </nettcpbinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://localhost:7997/WPFHost/tcp" binding="netTcpBinding">
                bindingConfiguration="NetTcpBinding_IChat" contract="SVC.IChat"
                name="NetTcpBinding_IChat" />
        </endpoint></client>
    </system.servicemodel>
</configuration>