【问题标题】:Can't Add Service Reference to a Project无法将服务引用添加到项目
【发布时间】:2015-06-24 15:28:30
【问题描述】:

我正在尝试将服务引用添加到已经有其他引用的项目。我已经复制了这些项目中使用的 App.Config 和 Web.config,并将它们调整为我想要添加的服务。我还复制并修改了合同,我相信我做得很好。

所以我的问题是:您认为我在添加服务引用时可能犯了哪些错误或常见错误,或者同样有帮助,我可以在哪里以及如何解决有关添加服务错误的问题引用带有 mex 端点的项目?

错误

错误详情

附加信息:

合约只作为一个操作(“开始”)。

正在通过 net.tcp 建立连接。

Service 和 Object 是不同的项目。

对象有一个 App.Config,服务有一个 Web.Config

更新

服务 Web.Config

 <?xml version="1.0"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\inetpub\SocketListener\logs\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>


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


  <system.serviceModel>
    <services>
      <service name="SocketListener.SocketListener">
        <endpoint address="" binding="netTcpBinding" contract="SocketListener.ISocketListener">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://<IP>/SocketListener/SocketListener.svc" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="netTcpBindingConf" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:05:00" hostNameComparisonMode="StrongWildcard" transactionFlow="false" transferMode="Buffered" maxBufferPoolSize="20000000"
            maxBufferSize="20000000"
            maxConnections="20000000"
            maxReceivedMessageSize="20000000"
            portSharingEnabled="true"
            listenBacklog="20000000">

        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" maxConcurrentInstances="200" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
</configuration>

【问题讨论】:

  • 显示服务配置
  • 嗨@burning_LEGION,感谢您的建议

标签: wcf net-tcp


【解决方案1】:

尝试将行为配置添加到服务:

<?xml version="1.0"?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\inetpub\SocketListener\logs\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>


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


  <system.serviceModel>
    <services>
      <service name="SocketListener.SocketListener" behaviorConfiguration="ServiceBeh">
        <endpoint address="" binding="netTcpBinding" contract="SocketListener.ISocketListener">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://<IP>/SocketListener/SocketListener.svc" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="netTcpBindingConf" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:05:00" hostNameComparisonMode="StrongWildcard" transactionFlow="false" transferMode="Buffered" maxBufferPoolSize="20000000"
            maxBufferSize="20000000"
            maxConnections="20000000"
            maxReceivedMessageSize="20000000"
            portSharingEnabled="true"
            listenBacklog="20000000">

        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBeh">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" maxConcurrentInstances="200" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
</configuration>

【讨论】:

  • 您好,我已经添加了behaviorConfiguration 属性,但它不起作用,我得到了同样的错误:/
  • mex 需要 serviceMetadata,在获取元数据时也应该继续工作服务,如果是远程 pc,则删除身份 localhost
  • 目前我正在同一台机器上进行测试,所以我需要保留身份 localhost。我认为这不是问题,会不会是其他问题?
  • 我认为您没有启动服务,因为服务、服务的行为配置和 mex 端点足以获取元数据。 cmd -> 网络统计。列表中是否包含服务?
  • 您好,burning_LEGION,如何通过 netstat 查看服务是否已启动并运行?我不知道如何检查服务的端口。 (附加信息是IIS中的应用程序使用http协议,应该使用net.tcp,我已经更改但错误仍然存​​在)
【解决方案2】:

此错误是由于文件 *.svc 的未配置和 IIS 中的未配置造成的

文件丢失配置

错误

<%@ ServiceHost Language="C#" Debug="true" Service="Service" %>

正确

<%@ ServiceHost Language="C#" Debug="true" Service="<Namespace>.<Class used in the Service>" %>

IIS MissConfiguration

错误

在 IIS 中部署的应用程序中, 在高级设置中, 我在启用的协议

中有http

正确

在 IIS 中部署的应用程序中, 在高级设置中, 我在启用的协议

中改为net.tcp

【讨论】:

    猜你喜欢
    • 2013-02-02
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 2012-02-15
    相关资源
    最近更新 更多