WCF:更改客户端凭据会产生“错误”;此工厂已启用手动寻址,因此发送的所有邮件必须预先寻址。”;
有人能帮忙吗,我正试图通过channel factory呼叫rest服务,但正在发送我的凭据。。。rest服务使用Windows身份验证 但通过下面的代码,我得到了“手动寻址在此工厂上启用,因此发送的所有消息都必须预先寻址。”使用GetMessage时出错 我知道我的服务就像我删除Windows身份验证一样有效!但在windows身份验证打开且不更改客户端凭据的情况下,我收到了错误的请求,我认为这是正常的。。。所以我需要发送我的客户凭据 我有点迷路了WCF:更改客户端凭据会产生“错误”;此工厂已启用手动寻址,因此发送的所有邮件必须预先寻址。”;,wcf,wcf-security,wcf-rest,Wcf,Wcf Security,Wcf Rest,有人能帮忙吗,我正试图通过channel factory呼叫rest服务,但正在发送我的凭据。。。rest服务使用Windows身份验证 但通过下面的代码,我得到了“手动寻址在此工厂上启用,因此发送的所有消息都必须预先寻址。”使用GetMessage时出错 我知道我的服务就像我删除Windows身份验证一样有效!但在windows身份验证打开且不更改客户端凭据的情况下,我收到了错误的请求,我认为这是正常的。。。所以我需要发送我的客户凭据 我有点迷路了 ChannelFactory<I
ChannelFactory<IService> cf = new ChannelFactory<IService>(new WebHttpBinding(), "http://localhost:8000");
var defaultCredentials = cf.Endpoint.Behaviors.Find<ClientCredentials>();
cf.Endpoint.Behaviors.Remove(defaultCredentials);
// step two - instantiate your credentials
ClientCredentials loginCredentials = new ClientCredentials();
loginCredentials.UserName.UserName = "Test";
loginCredentials.UserName.Password = "test";
// step three - set that as new endpoint behavior on factory
cf.Endpoint.Behaviors.Add(loginCredentials); //add required ones
IService channel = cf.CreateChannel();
Console.WriteLine(channel.GetMessage("Dhananjay Get"));
Console.WriteLine(channel.PostMessage("Dhananjay Post"));
ChannelFactory cf=新的ChannelFactory(新的WebHttpBinding(),”http://localhost:8000");
var defaultCredentials=cf.Endpoint.Behaviors.Find();
cf.Endpoint.Behaviors.Remove(defaultCredentials);
//第二步-实例化您的凭据
ClientCredentials loginCredentials=新的ClientCredentials();
loginCredentials.UserName.UserName=“测试”;
loginCredentials.UserName.Password=“测试”;
//第三步-将其设置为factory上的新端点行为
cf.Endpoint.Behaviors.Add(loginCredentials)//添加必需的
IService channel=cf.CreateChannel();
Console.WriteLine(channel.GetMessage(“Dhananjay Get”);
Console.WriteLine(channel.PostMessage(“达南杰邮报”);
您需要添加webHttp行为,并将该行为连接到您的端点。最终结果如下所示:
<system.serviceModel>
<services>
<service ...>
<endpoint behaviorConfiguration="webHttpBehavior" ...>
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
...
</system.serviceModel>
...
如果这没有帮助,请发布您的web.config。虽然这个问题有一个公认的答案,但我想我应该添加一些信息 由于
WebServiceFactory
类的GetQueryStringConverter
中存在错误(请参阅,如果通过参数传递对象数组,则不能使用
。相反,请将
元素添加到绑定中
客户端App.Config或Web.Config
服务Web.Config
...
至少,我必须将
添加到客户端和服务器。对于我来说,我需要将
添加到客户端的行为中
<behaviors>
<endpointBehaviors>
<behavior name="WebHttp_Behaviour">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<behaviors>
<serviceBehaviors>
...
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebHttp_EndPointBehaviour">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>