1

我正在尝试使用 IIS 7.5 在 win7 中创建 WCF NamedPipe。

  1. 在 IIS 管理器中右键单击,并创建名为“TestWCFWithNamedPipe”的网站
  2. 右键单击我的网站“TestWCFWithNamedPipe”-> 选择编辑绑定

    Type:http 
    Host Name:sample.localdev.net 
    Port:80 
    Address:*
    
    Type:net.pipe 
    Binding informations:*
    
  3. 在高级设置中,将启用协议的值设置为“http,net.pipe”

  4. 在我的网站“TestWCFWithNamedPipe”Web 应用程序项目中

web.config

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

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="DefaultBehavior">
                <serviceDebug />
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="DefaultBehavior" name="SampleWcfLib.SampleWcfObj">
            <endpoint address="net.pipe://localhost/Sample" binding="netNamedPipeBinding"
                bindingConfiguration="" contract="SampleWcfInterfaceLib.ISampleWcfObj" />
        </service>
    </services>
</system.serviceModel>

TestClient.exe代码如下

string address = "net.pipe://localhost/Sample";
NetNamedPipeBinding binding = new NetNamedPipeBinding(); 
EndpointAddress ep = new EndpointAddress(address);
ISampleWcfObj channel = ChannelFactory<ISampleWcfObj>.CreateChannel(binding, ep);
string result = channel.Ping("Test");

我跑TestClient.exe了,我得到了一个例外:

在 net.pipe://localhost/Sample 上没有可以接受消息的端点监听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。

我检查了 Win7 服务状态:

Net.Pipe Listener Adapter   Started
Net.Tcp Listener Adapter    Started

我已经完成了 WCF 的所有设置。

为什么我仍然收到EndpointNotFoundException错误消息?

4

1 回答 1

2

如果查看 XSD 文件,您可以找到 tcp 绑定的名称。它将位于文件的底部,看起来像这样

<wsdl:service name="PersonService">
   <wsdl:port name="NetNamedPipeBinding_IPersonContract" binding="tns:NetNamedPipeBinding_IPersonContract">
        <soap12:address location="net.pipe://wcftestpipe/WcfTest/PersonService.svc/test"/>
        <wsa10:EndpointReference>
             <wsa10:Address>net.pipe://wcftestpipe/WcfTest/PersonService.svc/test</wsa10:Address>
        </wsa10:EndpointReference>
   </wsdl:port>
</wsdl:service>

之后你可能会得到一个安全异常,它会说你没有正确的凭据。您可以在 WCF 服务的 web.config 和客户端的 app.config 中将绑定安全模式设置为 NONE。

<bindings>
    <netNamedPipeBinding>
      <binding>
        <security mode="None"/>
      </binding>
    </netNamedPipeBinding>
</bindings>

希望这可以帮助

于 2015-10-07T06:46:51.433 回答