C# 调用webservice错误An error was discovered processing the <wsse:Security> header
2021-03-31 11:24
标签:ado 错误 tom string asi add bind serialize process using System; namespace WebApplication1 public SecurityHeader(string id, string username, string password) public override string Name public override string Namespace protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) public UsernameToken(string id, string username, string password) [XmlAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")] [XmlElement] [XmlElement] public class Password [XmlAttribute] [XmlText] 调用 void Test(){ ServiceReference1.recvCustomer rc = new ServiceReference1.recvCustomer } 第二种方法: web.config直接配置 C# 调用webservice错误An error was discovered processing the 标签:ado 错误 tom string asi add bind serialize process 原文地址:https://www.cnblogs.com/zxk5625/p/9257671.html
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Web;
using System.Xml;
using System.Xml.Serialization;
{
public class SecurityHeader : MessageHeader
{
private readonly UsernameToken _usernameToken;
{
_usernameToken = new UsernameToken(id, username, password);
}
{
get { return "Security"; }
}
{
get { return "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; }
}
{
XmlSerializer serializer = new XmlSerializer(typeof(UsernameToken));
serializer.Serialize(writer, _usernameToken);
}
}
[XmlRoot(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public class UsernameToken
{
public UsernameToken()
{
}
{
Id = id;
Username = username;
Password = new Password() { Value = password };
}
public string Id { get; set; }
public string Username { get; set; }
public Password Password { get; set; }
}
{
public Password()
{
Type = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
}
public string Type { get; set; }
public string Value { get; set; }
}
}
{
reqInfo = "123",
reqData = "456"
};
ServiceReference1.WS_ESB_CustomerRecvPortTypeClient client = new ServiceReference1.WS_ESB_CustomerRecvPortTypeClient();
using (new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(
new SecurityHeader("UsernameToken-49", "username", "password"));
var ss= client.recvCustomer(rc);
}
contract="ServiceReference1.WS_ESB_CustomerRecvPortType" name="WS_ESB_CustomerRecvHttpSoap12Endpoint">
文章标题:C# 调用webservice错误An error was discovered processing the <wsse:Security> header
文章链接:http://soscw.com/index.php/essay/70430.html