WCF服务奇怪的错误 - 无法使用浏览器访问,可以通过客户端访问,但只能在调试时访问

时间:2012-08-28 07:23:49

标签: wcf

我目前正在学习WCF,我有一个非常奇怪的问题。

我已经创建了一个WCF服务并托管在一个控制台应用程序中。我创建了一个客户端,当我开始调试客户端时,一切都按预期工作。浏览器命中服务中指定的地址。 但是,当我在没有调试的情况下运行客户端时,我得到一个例外。 我没有碰过这项服务的整个时间。只有客户。该服务托管在控制台应用程序中。

我也注意到一些非常奇怪的事情。 我在客户端放了一个console.readline()。现在在调试客户端时,当我附加调试器时,我看到一个WCF服务桌面通知,告诉我托管服务,我能够使用该服务并且它可以工作。我也可以通过浏览器访问该地址。如果我分离调试器,地址在浏览器中不起作用。如果我重新连接然后再次工作,则会出现另一个桌面通知。这告诉我,当我仅调试时,我的服务已启动并正在运行。当我退出调试器时,服务退出。但我并没有触及服务,整个时间只是客户。

请告诉我,我并不疯狂:(

MyAddress:

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>

2 个答案:

答案 0 :(得分:2)

您需要在解决方案资源管理器中右键单击将在SVC中结束的文件标记为Visual Studio中项目的起始页。然后客户端将自动启动。

答案 1 :(得分:1)

客户端将需要控制台应用程序向其公开服务的端口。我想在运行调试器时,vs是在客户端成功连接的端口上托管。 (会添加此作为注释,但我的nexus客户端似乎不支持注释)尝试8733并且绑定应该匹配。