使用标头UserNameToken发送SOAP

时间:2018-05-07 14:30:21

标签: asp.net soap ws-security usernametoken

如何在SOAP标头中输入用户和密码以通过ASP.NET发送?

这应该是标题:

    <SOAP-ENV:Header>
<Security 
xmlns='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
    <UsernameToken>
        <Username>USUARIO</Username>
        <Password 
    Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>SENHA</Password>
    </UsernameToken>
</Security>  

我试过这种方式糟糕不起作用:

            string username = "USUARIO";
    string password = "SENHA";

    UsernameToken userToken;
    userToken = new UsernameToken(username, password, PasswordOption.SendHashed);

    PolicyEnforcementSecurityTokenCache.GlobalCache.Add(userToken);

    ServiceReference1.UpdateAccountRequest UpdateAccountRequest = new ServiceReference1.UpdateAccountRequest();
    ServiceReference1.UpdateAccountResponse UpdateAccountResponse = new ServiceReference1.UpdateAccountResponse();
    ServiceReference1.AccountResponse AccountResponse = new ServiceReference1.AccountResponse();

    ServiceReference1.SLASCRMAccountService_v1Client SLASCRMAccountService_v1Client = new ServiceReference1.SLASCRMAccountService_v1Client();
    ServiceReference1.SCRMAccount[] SCRMAccount = new ServiceReference1.SCRMAccount[] {
        new ServiceReference1.SCRMAccount {accountnumber = "99999999999", name = "FABIANO SOARES", telephone1 = "9999999", address1_line1 = "AV BRASILIA, 1024", address1_country = "BRASIL", dealer = "219", persontype = "1", address1_city = "ROLANDIA", address2_county = "PARANA", global_countrycode = "BR", global_accounttype = "1", global_sourcestatus = "Ativo", originsystem = "Datasul", relationtype = "3", cws = "Não" }
    };

    //SLASCRMAccountService_v1Client.ClientCredentials.UserName.UserName = username;
    //SLASCRMAccountService_v1Client.ClientCredentials.UserName.Password = password;

    AccountResponse =  SLASCRMAccountService_v1Client.UpdateAccount(SCRMAccount);

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Sucesso.!');", true);

错误信息是: System.ServiceModel.Security.MessageSecurityException:&#39; HTTP请求未在客户端身份验证方案中授权&#39;匿名&#39 ;.从服务器收到的身份验证标题是&#39; &#39;&#39;

0 个答案:

没有答案