我目前正在学习 WCF,但我遇到了一个非常奇怪的问题。
我创建了 WCF 服务并托管在控制台应用程序中。我创建了一个客户端,当我开始调试客户端时,一切都按预期工作。浏览器点击服务中指定的地址。但是,当我只运行客户端而不进行调试时,我得到了一个异常。我一直没有碰过这项服务。只有客户端。该服务托管在控制台应用程序中。
我还注意到一些非常奇怪的事情。我在客户端放了一个 console.readline() 。现在在调试客户端时,当我附加调试器时,我看到一个 WCF 服务桌面通知,告诉我服务已托管并且我能够使用该服务并且它可以工作。我也可以通过浏览器访问该地址。如果我分离调试器,地址在浏览器中不起作用。如果我重新附加然后它再次工作,另一个桌面通知出现。这告诉我我的服务仅在我调试时启动并运行。当我退出调试器时,服务退出。但我没有触及服务,整个时间只是客户。
请告诉我我没疯:(
我的地址:
http://localhost:8732/Design_Time_Addresses/MASService/Service1/
例外:在 [MyAddress] 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。
这是我的服务配置:
<?xml version="1.0" encoding="utf-8" ?>
<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="MASService.MasOperationsService" behaviorConfiguration="SimpleServiceBehavior">
<endpoint address="" binding="wsHttpBinding" contract="MASService.IMasOperations">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MASService/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这是我的服务主机配置(控制台应用程序):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MASService.MasOperationsService">
<endpoint address="http://localhost:8733/Design_Time_Addresses/MASService/Service1"
binding="basicHttpBinding" bindingConfiguration="" contract="MASService.IMasOperations" />
</service>
</services>
</system.serviceModel>
</configuration>
这是我的客户端配置(控制台应用程序):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMasOperations" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/Design_Time_Addresses/MASService/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMasOperations"
contract="ServiceReference1.IMasOperations" name="WSHttpBinding_IMasOperations">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>