本文介绍了WCF:更改 ClientCredentials 会产生“此工厂启用了手动寻址,因此所有发送的消息都必须预先寻址".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供帮助,我正在尝试通过通道工厂调用休息服务,但发送了我的凭据...休息服务使用 Windows 身份验证.

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.

但是使用以下代码,我得到该工厂启用了手动寻址,因此发送的所有消息都必须预先寻址."使用 GetMessage 时出错

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

我知道我的服务就像我删除了 Windows 身份验证一样有效!但是在打开 Windows 身份验证并且不更改 clientCredentials 的情况下,我收到了 BAD REQUEST,我认为这是正常的...所以我需要发送我的客户端凭据

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

我有点失落.

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

推荐答案

您需要添加一个 webHttp 行为,并将该行为连接到您的端点.最终结果将如下所示:

You need to add a webHttp behavior, and wire that behavior up to your endpoint. The end result will look something like this:

<system.serviceModel>
  <services>
    <service ...>
       <endpoint behaviorConfiguration="webHttpBehavior" ...>
       </endpoint>
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
    <behavior name="webHttpBehavior">
      <webHttp/>
    </behavior>
    </endpointBehaviors>
  </behaviors>
  ...
 </system.serviceModel>

如果这没有帮助,请发布您的 web.config.

If this doesn't help, please post your web.config.

这篇关于WCF:更改 ClientCredentials 会产生“此工厂启用了手动寻址,因此所有发送的消息都必须预先寻址".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 17:25