Hi, i am trying to call a webservice using HttpRequest as adding web reference not working for me. It asks for SOAP security header and its of wse type so i tried to call it through Httprequest. Here's my code and service request which works fine in
SOAPUI.
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("Webservice URL");
string strSOAPRequestBody = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zz=\"http://integration.starcite.com/\">"
+"<soapenv:Header>" +
"<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" +
"<wsse:UsernameToken wsu:Id=\"UsernameToken-1\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
"<wsse:Username>UserId</wsse:Username>" +
"<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">Password</wsse:Password>" +
"<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">rqgwyErTk7l5l7t1DqhdKw==</wsse:Nonce>"
+ "<wsu:Created>2013-05-31T17:49:07.888Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soapenv:Header>" +
"<zz:search-meeting-request>" +
"<filter from=\"0\" to=\"50\">" +
"<meetingId comparator=\"equal\">28</meetingId>" +
"</filter>" +
"</zz:search-meeting-request>" +
"</soapenv:Body>" +
"</soapenv:Envelope>";
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8";
request.ContentLength = strSOAPRequestBody.Length;
request.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)";
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter( request.GetRequestStream() );
streamWriter.Write( strSOAPRequestBody );
streamWriter.Close();
System.IO.StreamReader streamReader =
new System.IO.StreamReader(
request.GetResponse().GetResponseStream() );
string strResponse = "";
while( !streamReader.EndOfStream )
strResponse += streamReader.ReadLine();
streamReader.Close();
Following is the request that i put in SOAP UI and its working fine.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:zz="http://integration.starcite.com/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>UserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">rqgwyErTk7l5l7t1DqhdKw==</wsse:Nonce>
<wsu:Created>2013-05-31T17:49:07.888Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<zz:search-meeting-request>
<filter from="0" to="50">
<meetingId comparator="equal">28</meetingId>
</filter>
</zz:search-meeting-request>
</soapenv:Body>
</soapenv:Envelope>
Any help or guidance will be appreciated. Thanks