code_junkie

SOAP Client in C# without access to a WSDL-file

Nov 12th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. string EndPoints = "http://203.189.91.127:7777/services/spm/spm";
  2.  
  3. string New_Xml_Request_String = "<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><OTA_AirLowFareSearchRQ EchoToken="0" SequenceNmbr="0" TransactionIdentifier="0" xmlns="http://www.opentravel.org/OTA/2003/05"><POS xmlns="http://www.opentravel.org/OTA/2003/05"><Source AgentSine="" PseudoCityCode="NPCK" TerminalID="1"><RequestorID ID=""/></Source><YatraRequests><YatraRequest DoNotHitCache="true" DoNotCache="false" MidOfficeAgentID="" AffiliateID="" YatraRequestTypeCode="SMPA"/></YatraRequests></POS><TravelerInfoSummary><AirTravelerAvail><PassengerTypeQuantity Code="ADT" Quantity="1"/><PassengerTypeQuantity Code="CHD" Quantity="1"/><PassengerTypeQuantity Code="INF" Quantity="1"/></AirTravelerAvail></TravelerInfoSummary> <SpecificFlightInfo><Airline Code=""/></SpecificFlightInfo><OriginDestinationInformation><DepartureDateTime>" + DateTime.Now.ToString("o").Remove(19, 14) + "</DepartureDateTime><OriginLocation CodeContext="IATA" LocationCode="DEL">" + Source + "</OriginLocation><DestinationLocation CodeContext="IATA" LocationCode="BOM">" + Destincation + "</DestinationLocation></OriginDestinationInformation><TravelPreferences><CabinPref Cabin="Economy"/></TravelPreferences></OTA_AirLowFareSearchRQ></soapenv:Body></soapenv:Envelope>";
  4.  
  5.  
  6. protected string HttpSOAPRequest_Test(string xmlfile, string proxy)
  7. {
  8. try
  9. {
  10. System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  11. doc.InnerXml = xmlfile.ToString();
  12. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(EndPoints);
  13. req.Timeout = 100000000;
  14. if (proxy != null)
  15. req.Proxy = new WebProxy(proxy, true);
  16. req.Headers.Add("SOAPAction", "");
  17. req.ContentType = "application/soap+xml;charset="utf-8"";
  18. req.Accept = "application/x-www-form-urlencoded"; //"application/soap+xml";
  19. req.Method = "POST";
  20. Stream stm = req.GetRequestStream();
  21. doc.Save(stm);
  22. stm.Close();
  23. WebResponse resp = req.GetResponse();
  24. stm = resp.GetResponseStream();
  25. StreamReader r = new StreamReader(stm);
  26. string myd = r.ReadToEnd();
  27. return myd;
  28. }
  29.  
  30. catch (Exception se)
  31. {
  32. throw new Exception("Error Occurred in AuditAdapter.getXMLDocumentFromXMLTemplate()", se);
  33. }
  34. }
  35.  
  36. Imports Microsoft.Web.Services3
  37. Imports Microsoft.Web.Services3.Addressing
  38. Imports Microsoft.Web.Services3.Messaging
  39.  
  40. Namespace Logic
  41. Public Class HTTPClient
  42. Inherits Soapclient
  43.  
  44. Sub New(ByVal destination As EndpointReference)
  45. MyBase.Destination = destination
  46. End Sub
  47.  
  48. <SoapMethod("processConfirmation")> _
  49. Public Function processConfirmation(ByVal envelope As SoapEnvelope) As SoapEnvelope
  50. Return MyBase.SendRequestResponse("processConfirmation", envelope)
  51. End Function
  52. End Class
  53. End Namespace
  54.  
  55. Dim hc As New HTTPClient(New Microsoft.Web.Services3.Addressing.EndpointReference(New System.Uri("http://whatever.srv")))
  56.  
  57. Dim envelope As New Microsoft.Web.Services3.SoapEnvelope
  58. Dim doc As New Xml.XmlDocument
  59. doc.LoadXml("<hey>there</hey>")
  60. envelope.SetBodyObject(doc)
  61.  
  62. Dim return_envelope As Microsoft.Web.Services3.SoapEnvelope = hc.processConfirmation(envelope)
Add Comment
Please, Sign In to add comment