WCF:更改 ClientCredentials 会产生“此工厂启用手动寻址,因此发送的所有消息都必须预先寻址。”
任何人都可以帮忙,我正在尝试通过通道工厂调用休息服务,但发送我的凭据...休息服务使用 Windows 身份验证。
但通过以下代码,我得到“该工厂启用了手动寻址,因此发送的所有消息都必须预先寻址”。使用 GetMessage 时出错
我知道我的服务就像删除 Windows 身份验证一样工作!但是,在打开 Windows 身份验证并且不更改 clientCredentials 的情况下,我收到了 BAD REQUEST,我认为这是正常的...所以我需要发送我的客户端凭据,
我有点迷失了。
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"));
can anyone help, i am trying to call a rest service via the channel factory but sending along my credentials... The rest service uses Windows authentication.
But with the following code i get "Manual addressing is enabled on this factory, so all messages sent must be pre-addressed." error when using GetMessage
I know my service works as if i remove Windows authentication it works! BUt with windows authentication on and not changing clientCredentials i get BAD REQUEST whioch i think is normal... so i need to send along my client credentials
I am a little lost.
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"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要添加 webHttp 行为,并将该行为连接到您的端点。最终结果将如下所示:
如果这没有帮助,请发布您的 web.config。
You need to add a webHttp behavior, and wire that behavior up to your endpoint. The end result will look something like this:
If this doesn't help, please post your web.config.
尽管这个问题有一个公认的答案,但我想我应该添加一些信息。
由于
WebServiceFactory
类的GetQueryStringConverter
中存在错误(请参阅Microsoft Connect 报告),如果您通过,则无法使用
通过参数的对象数组。相反,请将
元素添加到绑定中。Client App.Config 或 Web.Config
Service Web.Config
至少,我必须向两个客户端添加
和服务器。Although this issue has an accepted answer, I thought I'd add a little information.
Because of the bug in
GetQueryStringConverter
of theWebServiceFactory
class (see Microsoft Connect report), you cannot use<WebHttp/>
if you are passing array's of objects through a parameter. Instead, add the<enableWebScript/>
element to the binding.Client App.Config or Web.Config
Service Web.Config
At least, I have had to add
<enableWebScript\>
to both client and server.对我来说,我需要将
添加到客户端的行为中。For me I needed to add
<webHttp/>
to Behaviours on client side.