我正在尝试使用VS2010向我的Web应用程序添加WCF服务引用.它似乎添加OK,但web.config没有更新,这意味着我得到一个运行时异常:
Could not find default endpoint
element that references contract
‘CoolService.CoolService’ 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.
显然,因为我的web.config中没有定义服务.重现步骤:
>右键单击解决方案>添加>新项目> ASP.NET空Web应用程序.
>右键单击新Web应用程序中的服务引用>添加服务参考.
>输入我的服务地址,然后单击“执行”.我的服务在左侧的“服务”部分中可见,我可以看到它的所有操作.
>为我的服务键入命名空间.
>单击“确定”.正确生成服务引用,我可以打开Reference.cs文件,看起来一切正常.
>打开web.config文件.它还是空的!
<system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <bindings /> <client /> </system.serviceModel>
为什么会这样?它也适用于控制台应用程序或我尝试的任何其他项目类型.有帮助吗?
这是我的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>