1

I get an error when trying to retrieve word document by webservice

            HttpWebRequest request;
            Uri uri = new Uri(serverUrl +
                    "/bare.aspx/" + Request.PathInfo);
            request = (HttpWebRequest)WebRequest.CreateDefault(uri);
            request.KeepAlive = false;
            request.AllowAutoRedirect = false;
            request.ReadWriteTimeout = -1;
            request.Timeout = -1;
            request.Credentials = System.Net.CredentialCache.DefaultCredentials;
            request.Method = "POST";
            request.ContentType = "application/octet-stream";

            // Serialize argument into request stream
            Hashtable arguments = new Hashtable();
            arguments["templateFile"] = templateFile;
            arguments["hSetDataSource"] = hSetDataSource;
            arguments["hSetRepeatBlock"] = hSetRepeatBlock;
            arguments["messageForEmptyWord"] = messageForEmptyWord;
            arguments["hImageBefore"] = hImageBefore;
            arguments["hImageAfter"] = hImageAfter;
            arguments["hImageInsideRepeater"] = hImageInsideRepeater;
            MemoryStream buf = new MemoryStream();
            BinaryFormatter fmt = new BinaryFormatter();
            fmt.Serialize(buf, arguments);
            request.ContentLength = buf.Length;
            Stream reqStream = request.GetRequestStream();
            buf.WriteTo(reqStream);
            reqStream.Close();
            buf.Close();                

            // Retreive word document from response and return it
            // TODO: refactor this to stream directly into the response 
            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();

When I check the webservice response (HttpWebResponse resp), I get the following error:

System.Net.WebException: The remote server returned an error: (404) Not Found.

I don't understand where is the problem, thank you in advance for your help.

RAS
  • 8,100
  • 16
  • 64
  • 86
TimeIsNear
  • 711
  • 4
  • 19
  • 38

1 Answers1

0

You are not hitting the endpoint. A 404 means the server could not find the URL you are requesting. Verify your .asmx URL by putting it in your web browser. If that works then make sure you code is using that same URL.

rick schott
  • 21,012
  • 5
  • 52
  • 81