首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将mex端点添加到NetNamedPipeBinding

将mex端点添加到NetNamedPipeBinding
EN

Stack Overflow用户
提问于 2013-06-13 06:19:31
回答 1查看 3.6K关注 0票数 4

我正在尝试通过NetNamedPipeBinding公开一个接口。

下面是我要做的:

代码语言:javascript
复制
        try
        {
            //load the shedluer static constructor
            ServiceHost svh = new ServiceHost(typeof(MyClass));

            var netNamedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            var netNamedPipeLocation = "net.pipe://localhost/myservice/";
            svh.AddServiceEndpoint(typeof(IMyInterface), netNamedPipeBinding, netNamedPipeLocation);

            // Check to see if the service host already has a ServiceMetadataBehavior
            ServiceMetadataBehavior smb = svh.Description.Behaviors.Find<ServiceMetadataBehavior>();
            // If not, add one
            if (smb == null)
                smb = new ServiceMetadataBehavior();

            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            svh.Description.Behaviors.Add(smb);

            // Add MEX endpoint
            svh.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                netNamedPipeLocation + "/mex"
                );

            svh.Open();

            Console.WriteLine("Service mounted at {0}", netNamedPipeLocation);
            Console.WriteLine("Press ctrl+c to exit");

            ManualResetEvent me=new ManualResetEvent(false);
            me.WaitOne();
            svh.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception");
            Console.WriteLine(e);
        }

服务启动正常,但当我创建一个新的Visual Studio项目并尝试在位置net.pipe://localhost/myservice/添加一个服务引用时,我得到了以下错误:

代码语言:javascript
复制
The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.pipe://localhost/myservice/'.
Metadata contains a reference that cannot be resolved: 'net.pipe://localhost/myservice/'.
If the service is defined in the current solution, try building the solution and adding the service reference again.

如果我用NetNamedPipeBinding代替TcpBinding,代码就能正常工作,并且可以添加服务引用。

我应该更改什么,才能在Visual Studio中添加服务引用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-13 07:28:31

var netNamedPipeLocation = "net.pipe://localhost/myservice/"; netNamedPipeLocation + "/mex"最终成为net.pipe://localhost/myservice//mex。您的AddServiceEndPoint调用应该是

代码语言:javascript
复制
svh.AddServiceEndpoint(
            ServiceMetadataBehavior.MexContractName,
            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
            netNamedPipeLocation + "mex"
            );

删除额外的/I后,可以连接到使用您的代码托管的本地命名管道服务,而没有出现问题。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17076364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档