将服务引用添加到 net.pipe 服务

发布于 2024-10-10 04:46:03 字数 1554 浏览 3 评论 0原文

我已经开始学习 WCF 并成功创建了一些测试 http 服务。现在,我尝试使用 net.pipe 绑定创建自托管 WCF 服务。下面是该服务的配置文件:-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <services>
        <service behaviorConfiguration="MEX" name="InProcService.MyService">
            <endpoint address="MyService"
                binding="netNamedPipeBinding" bindingConfiguration="" contract="InProcService.IMyService" />
            <endpoint address="Mex" binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.pipe://localhost/InProcService/" />
                    <add baseAddress="http://localhost:8001/InProcService/" />
                </baseAddresses>
            </host>
        </service>
    </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MEX"  >
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
</configuration>

现在在我的主机应用程序中,我使用以下方式启动服务:-

        ServiceHost host = new ServiceHost(typeof(MyService));
        host.Open();
        Console.WriteLine("Service started");

        host.Close();

执行此代码时,服务会正确启动。

现在,当在我的客户端应用程序中,我尝试将服务引用添加到此正在运行的服务时,它无法找到它。有什么我没有做或做得不正确的事情吗?

如果我能在这方面得到任何帮助,我将不胜感激。

干杯, 阿比。

I have started learning WCF and have created a few test http services successfully. Now, i was trying to create a self-hosted WCF service using net.pipe binding. Below is the configuration file for the service:-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <services>
        <service behaviorConfiguration="MEX" name="InProcService.MyService">
            <endpoint address="MyService"
                binding="netNamedPipeBinding" bindingConfiguration="" contract="InProcService.IMyService" />
            <endpoint address="Mex" binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.pipe://localhost/InProcService/" />
                    <add baseAddress="http://localhost:8001/InProcService/" />
                </baseAddresses>
            </host>
        </service>
    </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MEX"  >
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
</configuration>

Now in my host application, I am starting the service using:-

        ServiceHost host = new ServiceHost(typeof(MyService));
        host.Open();
        Console.WriteLine("Service started");

        host.Close();

The service starts correctly when this code is executed.

Now, when in my client application, I try to add the service reference to this running service, it is not able to find it. Is there something which I am not doing or doing incorrectly?

I would appreciate any help I can get on this.

Cheers,
Abhi.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倚栏听风 2024-10-17 04:46:03

该服务随后打开和关闭。当您启动客户端时,服务器已经关闭。所以在关闭之前需要 Console.ReadKey() 。

The service is opened and closed after that. By the time you start the client the server is already closed. So Console.ReadKey() is required is requied before close.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文