SOAP Webrequest Keep-Alive
-
Guten Tag,
Ich habe ein Problem. Ich muss ein SAP SOAP Service aufrufen.
Mit SoapUI und Fiddler habe ich herausgefunden, dass man 2 Requests schicken
muss.Beim 1. bekommt man eine not authorized Exception mit einem Cookie, mit
diesem Cookie muss man einen 2. Request schicken.allerdings fehlt beim 2. request den ich schicke,die Transport Connection
Keep-Alive Header Information ich habe keine Ahnung warum.
Vielleicht ein Code-Problem, oder vielleicht auch ein IIS Problem.Edit: Der untenstehende code ist bestandteil eine wcf services, der auf
einem IIS läuft.
Edit: Ich habe den Code in eine ConsolenAnwendung Kopiert, unverändert.
irgendetwas mache ich falschstring retval = string.Empty; XmlDocument SoapEnvelop = new XmlDocument(); SoapEnvelop.LoadXml(SapPerson.ToSoapXML(sappersons)); string authInfo = "blah" + ":" +"blub"; WebResponse response = null; SoapEnvelop.LoadXml(SapPerson.ToSoapXML(sappersons)); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxx"); request.Headers.Add("SOAPAction", "\"http://sap.com/xi/WebService/soap1.1\""); request.ContentType = "text/xml;charset=UTF-8"; request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); request.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)"; request.Method = "POST"; request.ServicePoint.Expect100Continue = false; try { request.GetResponse(); } catch (WebException wex) { response = wex.Response; } request = null; HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("http://xxx"); request2.Headers.Add("SOAPAction", "\"http://sap.com/xi/WebService/soap1.1\""); request2.ContentType = "text/xml;charset=UTF-8"; request2.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); request2.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)"; request2.Headers.Add("Server", "SAP NetWeaver Application Server 7.45 / AS Java 7.50"); request2.Method = "POST"; try { using (Stream s = request2.GetRequestStream()) { SoapEnvelop.Save(s); } } catch { } authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo.ToCharArray())); request2.Headers["Authorization"] = "Basic " + authInfo; request2.ServicePoint.Expect100Continue = false; string[] splitted = response.Headers[HttpResponseHeader.SetCookie].Split(';'); request2.Headers.Add("Cookie", splitted[0] + ";" + splitted[2].Split(',')[1]); request2.Headers.Add("Cookie2", "$" + splitted[splitted.Length - 2].Trim()); response.Close(); WebResponse response2 = null; try { response2 = request2.GetResponse(); } catch(WebException ex) { using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream())) { return sr.ReadToEnd(); } } using (StreamReader sr = new StreamReader(response2.GetResponseStream())) { retval = sr.ReadToEnd(); } return retval;
header request 1:
POST /XISOAPAdapter/xxx HTTP/1.1 SOAPAction: "http://sap.com/xi/WebService/soap1.1" Content-Type: text/xml;charset=UTF-8 Accept-Encoding: gzip,deflate User-Agent: Apache-HttpClient/4.1.1 (java 1.5) Host: xxx Connection: Keep-Alive
header request 2
POST /XISOAPAdapter/xxl HTTP/1.1 SOAPAction: "http://sap.com/xi/WebService/soap1.1" Content-Type: text/xml;charset=UTF-8 Accept-Encoding: gzip,deflate User-Agent: Apache-HttpClient/4.1.1 (java 1.5) Server: SAP NetWeaver Application Server 7.45 / AS Java 7.50 Host: xxx Authorization: Basic xxxx Cookie: xxx_url=POST#xxxxxx;xxxxx_*=(J2EE123456)1234567 Cookie2: $Version=1 Content-Length: 1589
Jemand eine Idee?