C# WCF错误:此工厂已启用手动寻址,因此发送的所有邮件都必须预先寻址
我有一个托管的WCF服务,我为其创建了一个自定义工厂,因此可以使用多个主机头:C# WCF错误:此工厂已启用手动寻址,因此发送的所有邮件都必须预先寻址,c#,wcf,messages,channelfactory,C#,Wcf,Messages,Channelfactory,我有一个托管的WCF服务,我为其创建了一个自定义工厂,因此可以使用多个主机头: /// <summary> /// Required for hosting where multiple host headers are present /// </summary> public class MultipleHostServiceFactory : ServiceHostFactory { protected override ServiceHost Create
/// <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());
}
}
错误发生在第
行返回base.Channel.GetData(值)代码>我认为这不一定与你们的工厂有关
看
或者是Bing最初几次点击“manualaddressing”中的其他内容。听起来所使用的绑定与堆栈/消息传递逻辑的某些其他部分不兼容。所以这终于结束了
布莱恩-谢谢你在这方面的指导。绑定在客户机和服务器上的b/t不一致,最后我在这两个方面都做了以下工作:
<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" />
因为这对我来说是一个相对较新的领域,所以只要解释一下为什么会出现这些错误,我就会朝着正确的方向前进:)。我遇到了这个错误,通过添加WebHttpBehavior(下面第2行)解决了这个问题:
var factory=newchannelfactory(new-WebHttpBinding(),uri);
添加(新的WebHttpBehavior());
var proxy=factory.CreateChannel();
我像往常一样添加了一个服务引用,但出现了此错误。事实证明,我所要做的就是修改客户机配置,使用行为指定为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>
好吧,我没有使用自定义竞价——使用web webHttpBinding——这两种方式都有定义。最初的问题是客户端只定义了自定义绑定(我只是对我的WCF服务器做了一个服务引用,让VS来完成其余的工作)。仍在研究这个新错误…“添加服务引用”和“webHttpBinding”不能很好地协同工作,这将解释错误。我认为您的客户机正在尝试使用WS-Addressing绑定与您的REST-y服务(只讲HTTP)进行SOAP对话。因此,使用svcuti.exe创建我的WCF客户机将是一个更好的途径?不;如果您使用的是webHttpBinding,那么svcutil和add服务引用都不好。你要么想手工编写客户端代码(共享合约类型等),要么使用一个只讲通用REST/CRUD接口的“通用”http客户端。好的,既然我要使用HTTPS,我就必须使用webHttpBinding吗?我只需要在这个主机上安装并运行一个基本的服务,这样我们就可以从那里开始了。嗯。。。我一加上它,就得到了(405)方法不允许
。上面的答案根本没有帮助。但你的解决方案奏效了。谢谢。如果端点已指定,则您需要改用WebScriptEnableBehavior,否则您将始终获得“故障状态”。这对我来说很有效,但我还必须为WebHttpBehavior添加一个using引用->using System.ServiceModel.Description
对于像我这样的人,如果你想让这个配置生效,你必须使用或者将“proxy”对象(上面的IService类型)注入到你的代码中。
var factory = new ChannelFactory<IService>(new WebHttpBinding(), uri);
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = factory.CreateChannel();
<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>