-1

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

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

错误 在此处输入图像描述

错误详情

在此处输入图像描述

附加信息:

合同仅作为一项操作(“开始”)。

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

服务和对象是不同的项目。

对象有一个 App.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>
4

2 回答 2

0

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

<?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>
于 2015-06-24T16:03:37.180 回答
0

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

文件丢失配置

错误的

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

正确的

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

IIS 错误配置

错误的

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

正确的

在 IIS 中部署的应用程序中,在高级设置中,我在启用的协议中更改为net.tcp

于 2015-06-25T13:56:29.613 回答