微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WCF 没有端点侦听 net.pipe://localhost/Ivan.WCFService.Lib/Service1 可以接受消息

如何解决WCF 没有端点侦听 net.pipe://localhost/Ivan.WCFService.Lib/Service1 可以接受消息

我在windows服务中托管了一个WCF服务,在同一台电脑上实现跨进程访问。 因此,采用了 netNamedPipBinding。 现在,在我的开发 PC 中一切正常(客户端可以通过端点访问 wcf 服务)。 但是当我将 client.exe、host.exe 和 wcf.dll 复制到另一台 PC 进行测试时。它不能工作并抛出这样的异常:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at net.pipe://localhost/Ivan.WCFService.Lib/MyService that Could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException,if present,for more details. ---> System.IO.PipeException: The pipe endpoint 'net.pipe://localhost/Ivan.WCFService.Lib/MyService' Could not be found on your local machine.
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.PipeConnectionInitiator.GetPipeName(Uri uri,IPipeTransportFactorySettings transportFactorySettings)
   at System.ServiceModel.Channels.NamedPipeConnectionPoolRegistry.NamedPipeConnectionPool.GetPoolKey(EndpointAddress address,Uri via)
   at System.ServiceModel.Channels.CommunicationPool`2.TakeConnection(EndpointAddress address,Uri via,TimeSpan timeout,TKey& key)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.Onopen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Onopen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel,TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout,CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object[] ins,Object[] outs,TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type)
   at Ivan.WCFService.Client.MyServiceReference.IMyService.QueryLinks()
   at Ivan.WCFService.Client.MyServiceReference.MyServiceClient.QueryLinks() in line 2547

所以这里是问题:

  1. 是否有遗漏需要复制的文件
  2. 异常指向端点。这是我的 wcf 服务库配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!-- 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="Ivan.WCFService.Lib.MyService">
        <endpoint address="MyService" binding="netNamedPipeBinding" contract="Ivan.WCFService.Lib.IMyService"/>
        <endpoint address="MyService/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.pipe://localhost/Ivan.WCFService.Lib"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing Metadata information,set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="False" httpsGetEnabled="False"/>
          <!-- 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>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>

在我的情况下,我不确定 baseAddress 是否应该由“localhost”设置。 并发布客户端配置文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
    <add key="ClientSettingsProvider.ServiceUri" value=""/>
  </appSettings>
  <system.web>
    <compilation debug="true"/>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider,System.Web.Extensions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider,PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
      </providers>
    </roleManager>
  </system.web>
    <system.serviceModel>
        <bindings>
            <netNamedPipeBinding>
              <binding name="NetNamedPipeBinding_IMyService" >
                <security mode="Transport">
                  <transport protectionLevel="EncryptAndSign" />
                </security>
              </binding>
            </netNamedPipeBinding>
        </bindings>
        <client>
            <endpoint address="net.pipe://localhost/Ivan.WCFService.Lib/MyService"
                binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IMyService"
                contract="MyServiceReference.IMyService" name="NetNamedPipeBinding_IMyService">
            </endpoint>
        </client>
    </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
  1. Win10 平台安全因素是否会影响此类端点?(已以管理员身份运行)
  2. 已经开启net.pip Listener Adapter服务,状态为running。 总之,这对配置文件可以在我的开发 PC 中正常运行。当我尝试在其他 PC 上对其进行测试时,它不会引发端点异常。有人可以帮忙吗?

解决方法

需要修改baseAddress:

           <endpoint address="net.pipe://The IP address of the WCF server/Ivan.WCFService.Lib/MyService"
                binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IMyService"
                contract="MyServiceReference.IMyService" name="NetNamedPipeBinding_IMyService">
            </endpoint>

如果客户端和服务器在同一台机器上,我们可以使用localhost。如果客户端和服务器不在同一台机器上,我们需要修改客户端的端点地址。如果此时客户端的访问端点地址还是 localhost 会报错。

需要修改客户端的端点地址,使其与WCF服务器的IP地址一致,然后重新编译。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。