tags:

views:

24

answers:

1
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'&gt;&lt;soap:Body&gt;&lt;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'&gt;&lt;soap:Body&gt;&lt;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'&gt;&lt;soap:Body&gt;&lt;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???

A: 

Internal Server Error simply means there's something wrong on the server. It usually means that the server has thrown an exception which was not handled.

Look in the Windows Event logs for an answer. In particular, look in the Application event log.

By the way, your code is pretty bad.

  • All the IDisposable classes should be instantiated in using blocks.
  • "throw ex" just messes up your stack. Get rid of that try/catch entirely.
John Saunders