WCF 错误:该工厂启用了手动寻址,因此发送的所有消息都必须预先寻址

发布于 2024-08-12 14:42:55 字数 943 浏览 11 评论 0原文

我有一个托管的 WCF 服务,我为其创建了一个自定义工厂,以便它可以与多个主机标头一起使用:

/// <summary>
/// Required for hosting where multiple host headers are present
/// </summary>
public class MultipleHostServiceFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        List<Uri> addresses = new List<Uri>();
        addresses.Add(baseAddresses[0]);
        return base.CreateServiceHost(serviceType, addresses.ToArray());
    }
}

我非常确定我的配置文件现在在客户端和服务器上都是正确的(可以在这里看到)。

我收到的错误似乎与工厂有关:

该工厂启用了手动寻址,因此发送的所有消息都必须预先寻址。

public string GetData(int value) {
    return base.Channel.GetData(value);
}

错误发生在 return base.Channel.GetData(value); 行。

I've got a hosted WCF service that I created a custom factory for, so that this would work with multiple host headers:

/// <summary>
/// Required for hosting where multiple host headers are present
/// </summary>
public class MultipleHostServiceFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        List<Uri> addresses = new List<Uri>();
        addresses.Add(baseAddresses[0]);
        return base.CreateServiceHost(serviceType, addresses.ToArray());
    }
}

I'm pretty sure that my config files are now right, on both client and server (can be seen here).

The error I'm getting appears to be related to the factory:

Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.

public string GetData(int value) {
    return base.Channel.GetData(value);
}

The error occurs at line return base.Channel.GetData(value);.

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

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

发布评论

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

评论(4

你爱我像她 2024-08-19 14:42:55

我遇到了这个错误,并通过添加 WebHttpBehavior(下面第 2 行)解决了问题:

var factory = new ChannelFactory<IService>(new WebHttpBinding(), uri);
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = factory.CreateChannel();

I experienced this error and the problem was resolved by adding the WebHttpBehavior (line 2 below):

var factory = new ChannelFactory<IService>(new WebHttpBinding(), uri);
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = factory.CreateChannel();
掩耳倾听 2024-08-19 14:42:55

我像往常一样添加了服务引用并收到了此错误。结果我所要做的就是修改客户端配置以使用具有指定 webhttp 行为的端点配置

<client>
  <endpoint address="http://localhost:9000/GeoConverterService/GeoConverterService.svc"
            binding="webHttpBinding" 
            contract="GeoConverter.IGeoConverterService" 
            behaviorConfiguration="webhttp"/>
</client>

<behaviors>
  <endpointBehaviors>
    <behavior name="webhttp">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

I added a service reference as usual and got this error. Turns out all I had to do was to amend the client config to use an endpoint config with a behaviour specifing webhttp

<client>
  <endpoint address="http://localhost:9000/GeoConverterService/GeoConverterService.svc"
            binding="webHttpBinding" 
            contract="GeoConverter.IGeoConverterService" 
            behaviorConfiguration="webhttp"/>
</client>

<behaviors>
  <endpointBehaviors>
    <behavior name="webhttp">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

怀中猫帐中妖 2024-08-19 14:42:55

我想这和你们工厂没有必然的关系。

请参阅

http://msdn.microsoft.com /en-us/library/system.servicemodel.channels.transportbindingelement.manualaddressing.aspx

或 Bing 搜索“manualaddressing”的前几个点击中的其他内容。听起来正在使用的绑定与堆栈/消息传递逻辑的其他部分不兼容。

I don't think this necessarily has anything to do with your factory.

See

http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.transportbindingelement.manualaddressing.aspx

or others among the first few Bing hits for "manualaddressing". It sounds like the binding being used is incompatible with some other portion of the stack/messaging logic.

筱果果 2024-08-19 14:42:55

所以这件事终于告一段落了!

布莱恩 - 感谢您对此的指导。客户端和服务器的绑定未对齐,我最终在两者中都进行了以下操作:

  <basicHttpBinding>
    <binding name="TransportSecurity">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding> 

...并相应地设置其端点绑定和绑定配置属性:

   <endpoint binding="basicHttpBinding" 
             bindingConfiguration="TransportSecurity"
             contract="ServiceReference1.IService" 
             name="WebHttpBinding_IService" 
             address="https://mysslserver.com/Service.svc" />

因为这对我来说是相对较新的领域,所以只需对为什么出现这些错误的解释引导我走向正确的方向:)。

So this has finally come to an end!

Brian - thanks for your guidance on this. The bindings were mis-aligned b/t the client and server, and I finally ended up going with the following in both:

  <basicHttpBinding>
    <binding name="TransportSecurity">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding> 

... and setting their endpoint binding and bindingConfiguration attributes accordingly:

   <endpoint binding="basicHttpBinding" 
             bindingConfiguration="TransportSecurity"
             contract="ServiceReference1.IService" 
             name="WebHttpBinding_IService" 
             address="https://mysslserver.com/Service.svc" />

Since this is relatively new turf for me, just the explanation of why those errors were popping up lead me in the right direction :).

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