我应该在“endpointConfigurationName”中指定什么DuplexClientBase 构造函数?

发布于 2025-01-07 16:23:12 字数 1772 浏览 0 评论 0原文

我应该在 DuplexClientBase 构造函数的“endpointConfigurationName”参数中指定什么?

无论我在那里放什么,客户端都会抛出这样的可执行文件:“在 ServiceModel 客户端配置部分中找不到引用合同“ServiceReference1.IClientFulfillmentPipeService”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。”

我使用“添加服务引用”向导生成了代理。以下是客户端的源代码:

class Program
{
    static void Main()
    {
        try
        {
            var client = new ClientFulfillmentPipeServiceClient(new InstanceContext(new Wrapper()), "*", "net.tcp://localhost:9000/svc");
            client.Initialize(1234, "Test");
            client.Close();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
}

我将示例 WCF 服务器编写为控制台应用程序。这是实现:

static void Main()
{
    UiWcfSession.OnInitialize += ClientInitialize;

    var baseAddresses = new Uri("net.tcp://localhost:9000/");

    var host = new ServiceHost(typeof(UiWcfSession), baseAddresses);

    var reliableSession = new ReliableSessionBindingElement { Ordered = true, InactivityTimeout = TimeSpan.MaxValue };
    var binding =
        new CustomBinding(reliableSession, new TcpTransportBindingElement()) { ReceiveTimeout = TimeSpan.MaxValue };

    host.AddServiceEndpoint(typeof(IClientFulfillmentPipeService), binding, "svc");

    var metadataBehavior = new ServiceMetadataBehavior();
    host.Description.Behaviors.Add(metadataBehavior);
    var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
    host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");

    host.Open();

    Thread.CurrentThread.Join();
}

private static void ClientInitialize(int uiprocessid, string key)
{
    Debug.WriteLine("ClientInitialize");
}

我没有使用 xml 配置。

请你帮助我好吗 ?

What should I specify in "endpointConfigurationName" parameter of DuplexClientBase constructor ?

No matter what I put there client throws execption that says "Could not find default endpoint element that references contract 'ServiceReference1.IClientFulfillmentPipeService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

I generated proxy using "Add Service Reference" wizard. Here is source code of the client:

class Program
{
    static void Main()
    {
        try
        {
            var client = new ClientFulfillmentPipeServiceClient(new InstanceContext(new Wrapper()), "*", "net.tcp://localhost:9000/svc");
            client.Initialize(1234, "Test");
            client.Close();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
}

And I have sample WCF server written as console application. Here is the implementation:

static void Main()
{
    UiWcfSession.OnInitialize += ClientInitialize;

    var baseAddresses = new Uri("net.tcp://localhost:9000/");

    var host = new ServiceHost(typeof(UiWcfSession), baseAddresses);

    var reliableSession = new ReliableSessionBindingElement { Ordered = true, InactivityTimeout = TimeSpan.MaxValue };
    var binding =
        new CustomBinding(reliableSession, new TcpTransportBindingElement()) { ReceiveTimeout = TimeSpan.MaxValue };

    host.AddServiceEndpoint(typeof(IClientFulfillmentPipeService), binding, "svc");

    var metadataBehavior = new ServiceMetadataBehavior();
    host.Description.Behaviors.Add(metadataBehavior);
    var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
    host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");

    host.Open();

    Thread.CurrentThread.Join();
}

private static void ClientInitialize(int uiprocessid, string key)
{
    Debug.WriteLine("ClientInitialize");
}

I'm not using xml configs.

Could you please help me ?

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

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

发布评论

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

评论(1

心安伴我暖 2025-01-14 16:23:12

看起来除非添加 .xml 配置文件,否则我无法使用此构造函数。

我最终使用了另一种以 CustomBindingEndpointAddress 作为参数的方法。

Looks like I can't use this constructor unless I add .xml config file.

I ended up using another one which takes CustomBinding and EndpointAddress as parameters.

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