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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1798069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 20:55:55  来源:igfitidea点击:

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

c#wcfmessageschannelfactory

提问by ElHaix

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

我有一个托管的 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());
    }
}

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);.

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

采纳答案by bendewey

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

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

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

回答by Brian

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

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.

或其他前几个必应点击“手动寻址”。听起来正在使用的绑定与堆栈/消息传递逻辑的其他部分不兼容。

回答by ElHaix

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:

...并相应地设置它们的端点绑定和 bindingConfiguration 属性:

   <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 :).

由于这对我来说是相对较新的领域,因此对为什么会出现这些错误的解释将我引向正确的方向:)。

回答by jason mardell

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

我像往常一样添加了服务引用并收到此错误。原来我所要做的就是修改客户端配置以使用具有指定 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>