当我通过提供我的Web服务引用来运行我的客户端服务时。它不会播放视频并下载它而是会出现如下错误:
错误
The content type video/mp4 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ' ftypmp42mp42mp41isomavc1"�moovlmvhd�x\R�x\RX:�@*iods���O����������ttrak\tkhd�x\R�x\R:�@@�$edtselst:��mdia mdhd�x\R�x\RwU�6hdlrvideL-SMASH Video Handler�minfvmhd$dinfdrefurl Nstbl�stsd�avc1@�HH AVC Coding��5avcCd��gd��AA���`h��,���paspsttswctts_D'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ServiceModel.ProtocolException: The content type video/mp4 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ' ftypmp42mp42mp41isomavc1"�moovlmvhd�x\R�x\RX:�@*iods���O����������ttrak\tkhd�x\R�x\R:�@@�$edtselst:��mdia mdhd�x\R�x\RwU�6hdlrvideL-SMASH Video Handler�minfvmhd$dinfdrefurl Nstbl�stsd�avc1@�HH AVC Coding��5avcCd��gd��AA���`h��,���paspsttswctts_D'.
这是我的服务代码,它完美地调用。
ASMX
public class Service : System.Web.Services.WebService
{
[WebMethod]
public List<UploadFile> GetUploadedFiles()
{
using (Database1Entities1 SampleDb = new Database1Entities1())
{
return SampleDb.UploadFiles.ToList();
}
}
[WebMethod]
public void ViewData(int File_ID)
{
using (Database1Entities1 SampleDb = new Database1Entities1())
{
var File = SampleDb.UploadFiles.Where(f => f.Id.Equals(File_ID)).FirstOrDefault();
if (File != null)
{
HttpContext.Current.Response.ContentType = File.ContentType;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + File.Name);
HttpContext.Current.Response.BinaryWrite(File.Content);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}}
}
} }
客户代码
public partial class _Default : Page
{
ServiceReference1.VideoWebServiceSoapClient client = new ServiceReference1.VideoWebServiceSoapClient();
protected void Page_Load(object sender, EventArgs e)
{
this.Form.Enctype = "multipart/form-data";
if (!IsPostBack)
{
DataGridView.DataSource = client.GetUploadedFiles();
DataGridView.DataBind();
}
}
protected void DataGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DownloadFile")
{
int File_ID = Convert.ToInt32(e.CommandArgument.ToString());
client.ViewData(File_ID);
}
}
任何人都可以解决这个问题.. ??