zoukankan      html  css  js  c++  java
  • WCF常见问题之端口共享

    当两个WCF应用程序想共享一个端口提供服务时,你会发现后一个启动的服务运行不了,会提示已经有应用程序在监听,如:

    应用一

    代码
    ServiceHost host = new ServiceHost(typeof(WCFPortSharing.AddService)); 
                NetTcpBinding binding 
    = new NetTcpBinding(); 
                host.AddServiceEndpoint(
    typeof(WCFPortSharing.IAddService), binding, "net.tcp://127.0.0.1:4503/addService"); 
                host.Open();

    应用二

    代码
    ServiceHost host1 = new ServiceHost(typeof(WCFPortSharing.SubService)); 
                NetTcpBinding binding1 
    = new NetTcpBinding(); 
                host1.AddServiceEndpoint(
    typeof(WCFPortSharing.ISubService), binding1, "net.tcp://127.0.0.1:4503/subService"); 
                host1.Open();

    如果想不冲突,需要开启WCF的端口共享,并启动一个服务Net.Tcp Port Sharing Service,此服务默认是禁止运行的,手动开启后,将服务配置加上

    binding.PortSharingEnabled = true;

    这样:

    代码
    ServiceHost host = new ServiceHost(typeof(WCFPortSharing.AddService)); 
                NetTcpBinding binding 
    = new NetTcpBinding(); 
                binding.PortSharingEnabled 
    = true
                host.AddServiceEndpoint(
    typeof(WCFPortSharing.IAddService), binding, "net.tcp://127.0.0.1:4503/addService"); 
                host.Open();
  • 相关阅读:
    yocto/bitbake 学习资源
    QEMU/KVM学习资源
    ubuntu 中创建和删除用户
    git 重命名本地和远程分支
    Ubuntu 上搭建 FTP 服务器
    gdb 常见用法
    git log 显示与特定文件相关的 commit 信息
    基于 qemu system mode 运行 arm 程序
    基于 qemu user mode 运行 aarch64 程序
    checking in(airport)
  • 原文地址:https://www.cnblogs.com/fx2008/p/2278354.html
Copyright © 2011-2022 走看看