Я создаю канал WCF для веб-клиента POX в коде, используя WebChannelFactory
. Я создал конфигурацию привязки в моем app.config
с базовым набором проверки подлинности, но когда я пытаюсь подключиться к конечной точке службы, базовая защита не применяется, и я получаю 401 с сервера.
Имя в моей конфигурации app.config
конечной точки и мои программные объявления совпадают. Я могу подтвердить это, потому что он правильно подбирает адрес.
Конечная точка службы бросает вызов безопасности BASIC, но ничего не происходит.
Нужно ли устанавливать конечную точку клиента wcfConfiguration?
Код
namespace AccountServices
{
[ServiceContract]
public interface IAccount
{
[OperationContract]
[WebGet(BodyStyle=WebMessageBodyStyle.Bare, ResponseFormat=WebMessageFormat.Xml, UriTemplate="?resourceId={resourceId}")]
XmlElement GetAccount(string resourceId);
}
public class AccountService
{
public XmlElement GetAccount(string resourceId, string userName, string password)
{
WebChannelFactory<ICPM> factory = new WebChannelFactory<IAccount>("AccountHttpClient");
if (!string.IsNullOrWhiteSpace(userName))
factory.Credentials.UserName.UserName = userName;
if (!string.IsNullOrWhiteSpace(password))
factory.Credentials.UserName.Password = password;
IAccount proxy = factory.CreateChannel();
try
{
return proxy.GetAccount(resourceId);
}
catch (System.ServiceModel.Security.MessageSecurityException securityEx)
{
throw;
}
}
}
}
Config
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="RawWebBinding" contentTypeMapper="">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="Basic"
realm="Login" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="pox">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://ENDPOINTADDRESS/"
behaviorConfiguration="pox" binding="webHttpBinding" bindingConfiguration="RawWebBinding"
contract="AccountServices.IAccount" name="AccountHttpClient" kind=""
endpointConfiguration="" />
</client>
</system.serviceModel>