webservice request issue with dynamic request inputs

Posted by nanda on Stack Overflow See other posts from Stack Overflow or by nanda
Published on 2010-03-17T06:12:53Z Indexed on 2010/03/17 6:21 UTC
Read the original article Hit count: 397

Filed under:
|
try
{
    const string siteURL = "http://ops.epo.org/2.6.1/soap-services/document-retrieval";
    const string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id='EP        1000000A1 I ' page-number='1' document-format='SINGLE_PAGE_PDF' system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";

    var request = (HttpWebRequest)WebRequest.Create(siteURL);
    request.Method = "POST";
    request.Headers.Add("SOAPAction", "\"document-retrieval\"");
    request.ContentType = " text/xml; charset=utf-8";


    Stream stm = request.GetRequestStream();
    byte[] binaryRequest = Encoding.UTF8.GetBytes(docRequest);
    stm.Write(binaryRequest, 0, docRequest.Length);
    stm.Flush();
    stm.Close();
    var memoryStream = new MemoryStream();
    WebResponse resp = request.GetResponse();
    var buffer = new byte[4096];
    Stream responseStream = resp.GetResponseStream();
    {
        int count;
        do
        {
            count = responseStream.Read(buffer, 0, buffer.Length);
            memoryStream.Write(buffer, 0, count);
        } while (count != 0);
    }
    resp.Close();
    byte[] memoryBuffer = memoryStream.ToArray();
    System.IO.File.WriteAllBytes(@"E:\sample12.pdf", memoryBuffer);

}
catch (Exception ex)
{
throw ex;
}

The code above is to retrieve the pdf webresponse.It works fine as long as the request remains canstant,

const string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id='EP        1000000A1 I ' page-number='1' document-format='SINGLE_PAGE_PDF' system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";

but how to retrieve the same with dynamic requests. When the above code is changed to accept dynamic inputs like,

[WebMethod]
public string DocumentRetrivalPDF(string docid, string pageno, string docFormat, string fileName)
{
    try
    {
         ........
         .......
         string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id=" + docid + " page-number=" + pageno + " document-format=" + docFormat + " system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";

         ......
         ........
     return "responseTxt";
    }
    catch (Exception ex)
    {
        return ex.Message;
    }

  }

It return an "INTERNAL SERVER ERROR:500" can anybody help me on this???

© Stack Overflow or respective owner

Related posts about c#

Related posts about asmx