HTML   发布时间:2022-04-14  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了添加WCF服务引用时,不会将配置详细信息添加到web.config大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用VS2010向我的Web应用程序添加WCF服务引用.它似乎添加OK,但web.config没有更新,这意味着我得到一个运行时异常: @H_874_2@显然,因为我的web.config中没有定义服务.重现步骤:

@H_874_2@>右键单击解决方案>添加>新项目> ASP.NET空Web应用程序.
>右键单击新Web应用程序中的服务引用>添加服务参.
>输入我的服务地址,然后单击“执行”.我的服务在左侧的“服务”部分中可见,我可以看到它的所有操作.
>为我的服务键入命名空间.
>单击“确定”.正确生成服务引用,我可以打开Reference.cs文件,看起来一切正常.
>打开web.config文件.它还是空的!

<system.web>
    <compilation debug="true" targetFramework="4.0" />
</system.web>


<system.serviceModel>
    <bindings />
    <client />
</system.serviceModel>
@H_874_2@为什么会这样?它也适用于控制台应用程序或我尝试的任何其他项目类型.有帮助吗?

@H_874_2@这是我的WCF服务的app.config:

<?xml version="1.0"?>

<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project,the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>

    <services>

      <service name="CoolSQl.Server.WCF.Coolservice">

        <endpoint address=""
          binding="webhttpBinding"
          contract="CoolSQl.Server.WCF.Coolservice"
          behaviorConfiguration="SilverlightFaultBehavior">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>

        <endpoint address="mex"
          binding="mexhttpBinding"
          contract="IMetadataExchange" />

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/CoolSQl.Server.WCF/Coolservice/" />
          </baseAddresses>
        </host>

      </service>

    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webhttp />
        </behavior>
        <behavior name="SilverlightFaultBehavior">
          <silverlightFaults />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>

      <webhttpBinding>
        <binding name="DefaultBinding"
          bypassProxyOnLocal="true"
          useDefaultWebProxy="false"
          hostNameComparisonMode="WeakWildcard"
          sendTimeout="00:05:00"
          openTimeout="00:05:00"
          receiveTimeout="00:00:10"
          maxReceivedmessageSize="2147483647"
          transferMode="Streamed">
          <readerQuotas maxArrayLength="2147483647"
            maxStringContentLength="2147483647" />
        </binding>
      </webhttpBinding>

    </bindings>

    <extensions>
      <behaviorExtensions>
        <add name="silverlightFaults"
          type="CoolSQl.Server.WCF.SilverlightFaultBehavior,CoolSQl.Server.WCF" />
      </behaviorExtensions>
    </extensions>

    <diagnostics>
      <messageLogging logEntiremessage="true"
        logMalformedmessages="false"
        logmessagesAtserviceLevel="true"
        logmessagesAtTransportLevel="false"
        maxmessagesToLog="3000"
        maxSizeOfmessageToLog="2000" />
    </diagnostics>

  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0"
      sku=".NETFramework,Version=v4.0" />
  </startup>

  <system.diagnostics>
    <sources>
      <source name="System.serviceModel.messageLogging"
        switchValue="Information,ActivityTracing">
        <listeners>
          <add name="messages"
            type="System.Diagnostics.XmlWriterTraceListener"
            initializeData="c:\messages.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

</configuration>

解决方法

发现了如何解决这个问题.我的WCF服务在其自己的项目中实现,并由同一解决方案中的单独控制台应用程序托管.如果我将WCF服务作为解决方案的启动项目运行(例如,让VS为我托管),那么添加引用工作正常,并将正确的行添加到客户端web.config.但是如果我从我的控制台应用程序中托管服务,然我仍然可以添加引用,但客户端的web.config不会被修改.因此,解决方法是先让VS托管服务,然后添加引用,然后在控制台应用程序中更改要托管的服务(在同一地址和端口). @H_874_2@这是令人惊讶的行为,我很好奇是否有人可以解释它?

大佬总结

以上是大佬教程为你收集整理的添加WCF服务引用时,不会将配置详细信息添加到web.config全部内容,希望文章能够帮你解决添加WCF服务引用时,不会将配置详细信息添加到web.config所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。