0
[WebMethod()] public void GetFileByDocumentNumber(string DocumentNumber) { string FilePath = GetFile(DocumentNumber); string FullPath = ConfigurationManager.AppSettings["FilePath"] + FilePath; DownloadToBrowser(FullPath); } private void DownloadToBrowser(string filePath) { FileInfo file = new FileInfo(filePath); Context.Response.Clear(); Context.Response.ClearHeaders(); Context.Response.ClearContent(); Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Context.Response.AddHeader("Content-Length", file.Length.ToString()); Context.Response.ContentType = "text/plain"; Context.Response.Flush(); Context.Response.TransmitFile(file.FullName); Context.Response.End(); } 

I'm using above code for my web service in order to download a file from the server.it's working fine in the local machine but when i host my webservice on a server and try to consume the service it gives the following error

Client found response content type of 'text/plain', but expected 'text/xml'. 

whats the reason for this error?

1
  • FYI, were you aware that ASMX web services (what you're using) are a legacy technology that should not be used for new development? Commented Jul 30, 2012 at 18:30

2 Answers 2

1

You should have to return a file content via WebMethod.

[WebMethod()] public string GetFileByDocumentNumber(string DocumentNumber) { string FilePath = GetFile(DocumentNumber); string FullPath = ConfigurationManager.AppSettings["FilePath"] + FilePath; return File.ReadAllText(FullPath); } 
Sign up to request clarification or add additional context in comments.

Comments

1

Try to replace ContentType with application/octet-stream.

1 Comment

it gives the error."Client found response content type of 'application/octet-stream', but expected 'text/xml'."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.