Mik*_*ain 9 wcf visual-studio-2010
我正在尝试使用VS2010向我的Web应用程序添加WCF服务引用.它似乎添加OK,但web.config没有更新,这意味着我得到一个运行时异常:
无法在ServiceModel客户端配置部分中找到引用合同"CoolService.CoolService"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.
显然,因为我的web.config中没有定义服务.重现步骤:
打开web.config文件.它还是空的!
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
为什么会这样?它也适用于控制台应用程序或我尝试的任何其他项目类型.有帮助吗?
这是我的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>
Run Code Online (Sandbox Code Playgroud)
我发现了如何解决这个问题。我的 WCF 服务是在其自己的项目中实现的,并由同一解决方案中的单独控制台应用程序托管。如果我将 WCF 服务作为解决方案的启动项目运行(例如,让 VS 为我托管它),那么添加引用就可以正常工作,并且正确的行将添加到客户端 web.config 中。但是,如果我在控制台应用程序中托管服务,虽然我仍然可以添加引用,但客户端的 web.config 不会被修改。因此,解决方法是首先让 VS 托管该服务,然后添加引用,然后在控制台应用程序中更改要托管的服务(在相同的地址和端口)。
这是令人惊讶的行为,我很好奇是否有人可以阐明这一点?
| 归档时间: |
|
| 查看次数: |
14392 次 |
| 最近记录: |