Click here to Skip to main content
15,887,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am calling my web service for this format my request parameter with soap format like this



XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IMessageContract/GetAuthorInfo</Action>
    <h:AuthorIdentity xmlns:h="http://tempuri.org/">db2972</h:AuthorIdentity>
  </s:Header>
  <s:Body>
    <AuthorRequest xmlns="http://tempuri.org/" />
  </s:Body>
</s:Envelope>




and i am calling this web service for code behind so give me the error like this
The remote server returned an error: (400) Bad Request.

So please give me the suggestion for this


C#
string resultXml;
          const string url = "http://localhost:50399/MessageContract.svc";
          WebRequest wbrqst = WebRequest.Create(url);
          HttpWebRequest httpreq = (HttpWebRequest)wbrqst;
          httpreq.Method = "POST";
          httpreq.ContentType = "text/xml";
          httpreq.Headers.Add("SOAPAction", url);
          httpreq.ProtocolVersion = HttpVersion.Version11;
          httpreq.Credentials = CredentialCache.DefaultCredentials;
          Stream requestStream = httpreq.GetRequestStream();
          StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
          StringBuilder sb = new StringBuilder();
          sb.Append("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
          sb.Append("<s:Header>");
          sb.Append("<Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/IMessageContract/GetAuthorInfo</Action>");
          sb.Append("<h:AuthorIdentity xmlns:h=\"http://tempuri.org/\">db2972</h:AuthorIdentity>");
          sb.Append("</s:Header>");
          sb.Append("<s:Body>");
          sb.Append("<AuthorRequest xmlns=\"http://tempuri.org/\" />");
          sb.Append("</s:Body>");
          sb.Append("</s:Envelope>");
          streamWriter.Write(sb.ToString());
          streamWriter.Close();

          HttpWebResponse wr = (HttpWebResponse)httpreq.GetResponse();
          StreamReader srd = new StreamReader(wr.GetResponseStream());
          resultXml = srd.ReadToEnd();
Posted
Updated 6-Nov-15 6:12am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900