0
我有這個錯誤,當我嘗試使用遠程wcf服務創建新用戶時,其他服務正常工作。 {「HTTP請求被禁止,客戶端認證方案'Basic'。」}。HTTP請求被禁止,客戶端身份驗證方案'Basic'
我的用戶控制器
[AcceptVerbs("Post")]
public ActionResult Add(FormCollection collection)
{
_userRepository.Add(collection["Company"], collection["Email"], collection["ExternalIdentifier"]);
return RedirectToAction("LoggedInAsAdministrator", "Home");
}
我的用戶信息庫
public void Add(string company, string email, string eid)
{
var user = new User { Company = company, Email = email, ExternalIdentifier = eid, AccountType = "pro", CountryCode = "NL", Language="EN" };
var createdUser = _proxy.CreateUser(user);
((IDisposable)_proxy).Dispose();
}
我user.cs:
[ServiceContract]
[XmlRoot("user")]
public class User
{
[XmlElement("company")]
public string Company { get; set; }
[XmlElement("country-code")]
public string CountryCode { get; set; }
[XmlElement("language")]
public string Language { get; set; }
[XmlElement("created-at")]
public DateTime? CreatedAt { get; set; }
[XmlElement("email")]
public string Email { get; set; }
[XmlElement("external-identifier")]
public string ExternalIdentifier { get; set; }
[XmlElement("id")]
public int? Id { get; set; }
[XmlElement("measurement-system")]
public string MeasurmentSystem { get; set; }
[XmlElement("profile")]
public string Profile { get; set; }
[XmlElement("url")]
public string Url { get; set; }
[XmlElement("username")]
public string Username { get; set; }
[XmlElement("account-type")]
public string AccountType { get; set; }
[XmlElement("current-token")]
public string CurrentToken { get; set; }
}
我servermodel配置
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="xxxxxxx" binding="webHttpBinding" bindingConfiguration="UsernameWithTransport" behaviorConfiguration="xxxxx" contract="xxxxx" name="xxxxx" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="xxxxxxxx">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
任何幫助,請。
我打電話的工廠實例的用戶名和密碼時,我實例化我的用戶資源庫,這不是probleme – dardouri90
你能後的代碼,您是如何設置的服務代理憑據? –
這就是我所說的渠道工廠: private readonly ChannelFactory _factory; private readonly IxxxApi _proxy; public UserRepository() { _factory = xxxFactory.GetxxxCatory(); _proxy = _factory.CreateChannel(); } –
dardouri90