.NET client authentication and SOAP credential headers for a CXF web service

前端 未结 1 1132
时光取名叫无心
时光取名叫无心 2021-01-03 03:07

SCENARIO

I have to access a web service with a .NET client. The service is an Apache CXF Web Service. Username and password authentication is requir

1条回答
  •  情话喂你
    2021-01-03 03:30

    Eventually I had to invoke the service creating the whole SOAP message and making an HttpWebRequest. In the SOAP message I manually specify the security header:

    
      
         
            Foo
            Bar
            qM6iT8jkQalTDfg/TwBUmA==
            2012-06-28T15:49:09.497Z
         
      
    
    

    And here the service client:

    String Uri = "http://web.service.end.point"
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Uri);
    req.Headers.Add("SOAPAction", "\"http://tempuri.org/Register\"");
    req.ContentType = "text/xml;charset=\"utf-8\"";
    req.Accept = "text/xml";
    req.Method = "POST";
    
    String SoapMessage = "MySoapMessage, including envelope, header and body"
    using (Stream stm = req.GetRequestStream())
    {
        using (StreamWriter stmw = new StreamWriter(stm))
        {
            stmw.Write(SoapMessage);
        }
    }
    
    
    try
    {
        WebResponse response = req.GetResponse();
        StreamReader sr = new StreamReader(response.GetResponseStream());
        log.InfoFormat("SoapResponse: {0}", sr.ReadToEnd());
    }
    catch(Exception ex)
    {
        log.Error(Ex.ToString());
    }
    

    Interesting resources about Web Service Security (WSS):

    • Wikipedia
    • OASIS

    0 讨论(0)
提交回复
热议问题