参数名称:内部错误:MessageContract的实例不能为空

本文关键字:不能 实例 错误 内部 参数 MessageContract | 更新日期: 2023-09-27 18:05:10

我使用的是jqgrid 4.3.3。下面是jqgrid的代码

function ExaminationDocumentGridList(ExaminationId) {
    var url1 = '../PIMSRecords/GetExamDocument?ExaminationId=' + ExaminationId;
    $("#PersonExaminationDocList").jqGrid({
        url: url1,
        datatype: 'json',
        mtype: 'POST',
        colNames: ['RowId', 'sId', 'pID', 'Document Name', 'Document No', 'Validated By', 'Validated Date', '', '', ''],
        colModel: [
              { name: 'rowId', index: 'rowId', hidden: true, width: 65 },
              { name: 'PersonExamDocId', index: 'PersonExamDocId', hidden: true, width: 20, align: 'left' },
              { name: 'ExaminationId', index: 'ExaminationId', hidden: true, width: 65 },
              { name: 'PersonExamName', index: 'PersonExamName', width: 150, align: 'left' },
              { name: 'PersonExamNo', index: 'PersonExamNo', width: 90, align: 'center' },
              { name: 'ValidatedBy', index: 'ValidatedBy', width: 150, align: 'center' },
              { name: 'ValidatedDate', index: 'ValidatedDate', sortable: false, width: 100, align: 'center' },
              { name: 'fileextension', index: 'fileextension', hidden: true, sortable: false, width: 70, align: 'center' },
              { name: 'ImageReportId', index: 'ImageReportId', hidden: true, sortable: false, width: 70, align: 'center' },
              { name: 'ImageFileName', index: 'ImageFileName', hidden: true, sortable: false, width: 70, align: 'center' }
              ],
        pager: $('#PersonExaminationDocPager'),
        rowNum: 3,
        rowList: [3, 6, 12],
        sortname: 'ValidatedDate',
        sortorder: "desc",
        viewrecords: true,
        height: '100%',
        onSelectRow: function (id) {
            var objRowData = jQuery("#PersonExaminationDocList").getRowData(id);
            var PersonExamName = objRowData.PersonExamName;
            var PersonExamNo = objRowData.PersonExamNo;
            var ValidatedBy = objRowData.ValidatedBy;
            var ValidatedDate = objRowData.ValidatedDate;
            var docid = objRowData.ImageReportId;
            var docname = objRowData.ImageFileName;
            var fileextension = objRowData.fileextension;
            $("#hidExamDocImageReportId").val(docid);
            $("#hidExamDocImageFileName").val(docname);
            $("#PersonExamName").val(PersonExamName);
            $("#PersonExamNo").val(PersonExamNo);
            $("#divSignatoryId #HRHead option:contains(" + ValidatedBy + ")").attr('selected', 'selected');
            $("#ValidatedDate").val(ValidatedDate);
            var url = '../PIMSRecords/_ExaminationDoc/' + objRowData.PersonExamDocId;
            var pId = objRowData.PersonExamDocId;
            $("#hidEntryPersonExamDocId").val(pId);
            viewpartialExamdocs(url, "partialExamDoc");
        },
        loadComplete: function () {
            /*gets the ids of grid */
            var ids = jQuery("#PersonExaminationDocList").getDataIDs();
            /*gets the number of rows of the Grid */
            var len = ids.length, newLine;
            if (len < 3) {
                /*Make a blank newlineData */
                /*Calls the function to add row data */
                AddNewRowToGridLISTOFDOCUMENT(len, '#PersonExaminationDocList');
            }
        }
    });
}

对于函数

function viewpartialExamdocs(url, partialDocumentPreview) {
    $.ajax({
        type: "POST",
        url: url,
        data: {},
        success: function (response) {
            $("#" + partialDocumentPreview + "").html(response);
            var fileId = $("#hidExamDocImageReportId").val();
            var filename = $("#hidExamDocImageFileName").val();
            fileextension = filename.substr(filename.lastIndexOf('.') + 1, 4);
            if (fileextension == 'pdf') {
                $("#EmpExamimgFirstPreview").hide();
                $("#EmpExamiFrameFirstPreview").show();
                var varsrc = "../UploadDownload/_ViewPDF?&fId=" + fileId + "&filename=" + filename;
                $("#EmpExamDocFrameId").attr('src', varsrc);
                $("#ExamDocPreviewFrameId").attr('src', varsrc);
            } else {
                $("#EmpExamimgFirstPreview").show();
                $("#EmpExamiFrameFirstPreview").hide();
            }
        },
        error: function (response) {
            alert("error" + response);
        },
        datatype: "html"
    });
}

这是我的控制器

[HttpPost]
    public ActionResult _ExaminationDoc(int id)
    {
        ViewData["ExaminationDoc"] = _or.GetPersonExamDoc(id);
        return PartialView("_ExaminationDoc", ViewData["ExaminationDoc"]);
    }

这里是控制器获取的数据

public PersonExaminationDocument GetPersonExamDoc(int id)
    {
        var examdoc = (from ed in db.PersonExaminationDocuments
                       where ed.PersonExamDocId == id
                    select ed).SingleOrDefault();
        return examdoc;
    }

此代码用于查看图片

    @model PIMS.Models.PersonExaminationDocument
<center>
    <fieldset style="width: 160px; height: 250px">
        <legend style="text-align: left; font-style: normal; font-weight: bold; font-family: Arial;
            font-size: 12px;">Document Preview</legend>
        <div id="EmpExamimgFirstPreview">
            @if (Model != null)
            {
                if (Model.ImageReportId != null)
                {
                <img  alt="ExamDoc" id="ExamDocimg"  height="220px" width="150px" src="@Url.Action("Download", "UploadDownload", new { @id = Model.ImageReportId, @fname = Model.ImageFileName })" />                                                           
                }
                else
                {
                <img  alt="ExamDoc" id="ExamDocimg"  height="220px" width="150px" src="@Url.Content("~/Content/Images/document_preview.png")"/> 
                }
            }
            else
            {
                <img  alt="ExamDoc" id="ExamDocimg"  height="220px" width="150px" src="@Url.Content("~/Content/Images/document_preview.png")"/> 
            }
        </div>
        <div id="EmpExamiFrameFirstPreview" runat="server" style="display: none">
            <iframe id="EmpExamDocFrameId" style="width: 150px; height: 220px;"></iframe>
        </div>
    </fieldset>
</center>
<input id="hidImageId" type="hidden" />
<input id="hidFNameId" type="hidden" />
<input id="hidExamuploadedDoc" type="hidden" />
<input id="hidExamDocsExtensionid" type="hidden" />

这是下载图片查看的代码和我的错误

public ActionResult Download(Guid id, string fname)
    {           
        FileTransferServiceClient client = new FileTransferServiceClient();
        DownloadRequest dr = new DownloadRequest();         
        RemoteFileInfo rmi = new RemoteFileInfo();            
        Stream stream = null;
        string pId = id.ToString();
        string Userkey = "gHeOai6bFzWskyUxX2ivq4+pJ7ALwbzwF55dZvy/23BrHAfvDVj7mg";
        string PassKey = "lLAHwegN8zdS7mIZyZZj+EmzlkUXkvEYxLvgAYjuBVtU8sw6wKXy2g";          
        client.Open();          
        rmi = client.DownloadFile(ref pId, ref fname, ref PassKey, ref  Userkey);  -------- Here is where i get my error why?
        stream = rmi.FileByteStream;         
        MemoryStream writeStream = new MemoryStream();
        Int32 chunksize = 2048;         
        Byte[] buffer = new Byte[chunksize];          
        do
        {
            Int32 bytesRead = stream.Read(buffer, 0, chunksize);
            if (bytesRead == 0)
            {
                break;
            }
            writeStream.Write(buffer, 0, bytesRead);
        } while (true);
        client.Close();       
        string ext1 = Getextension(fname);
        string ext = ext1.ToLower();
        string contentType = "image/png";          
        if ((ext == "jpeg") || (ext == "png"))
        {
            contentType = "image/png";
        }
        else if ((ext == "gif"))
        {
            contentType = "image/gif";
        }
        else if (ext == "txt")
        {
            contentType = "text/html";
        }
        else if ((ext == "doc") || (ext == "docx"))
        {
            contentType = "application/msword";
        }
        else if ((ext == "ppt") || (ext == "pptx"))
        {
            contentType = "application/vnd.ms-powerpoint";
        }
        else if (ext == "pdf")
        {
            contentType = "application/pdf";
        }
        else if ((ext == "mp3"))
        {
            contentType = "audio/mpeg";
        }
        else if (ext == "mp4")
        {
            contentType = "video/mp4";
        }
        else if (ext == "flv")
        {
            contentType = "video/x-flv";
        }
        else if (ext == "wmv")
        {
            contentType = "application/x-ms-wmv";
        }
        var imageBytes = writeStream.ToArray();
        if (imageBytes == null)
        {
            return new FilePathResult("~/Content/Images/btn_mtops_pic.png", "image/png");
        }
        else
        {
            FileContentResult file = new FileContentResult(imageBytes, contentType);
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fname);
            return file;
        }
    }

我的TFS http://192.168.120.11:600/FTServices.svc/basic也有这个

是我得到的错误。有人知道吗?请帮助。谢谢。

参数名称:内部错误:MessageContract的实例不能为空

这是我得到的完整错误消息:

Value不能为空。

参数名称:Internal Error: MessageContract的实例

在System.ServiceModel.Dispatcher.OperationFormatter.TypedMessageParts . .ctor(对象实例,MessageDescription描述)

在System.ServiceModel.Dispatcher.OperationFormatter

。SerializeReply(MessageVersion MessageVersion, Object[] parameters, Object result)

System.ServiceModel.Dispatcher.DispatchOperationRuntime.SerializeOutputs (MessageRpc&rpc)

System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin (MessageRpc&rpc)

System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5 (MessageRpc&rpc)

System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11 (MessageRpc&rpc)

在System.ServiceModel.Dispatcher.MessageRpc

。过程(布尔isOperationContextSet)

原来这个问题是由试图从我的WCF服务返回一个空值引起的,(例如通过WCF通道发送null)。

在调试时,我注意到当试图通过客户端传递null作为参数时,我也可以触发一个非常类似的错误消息。

当客户端试图发送一个空参数时,错误看起来像这样:

系统。ArgumentNullException: Value不能为空。

参数名:内部错误:MessageContract的实例不能为空

服务器堆栈跟踪:

在System.ServiceModel.Dispatcher.OperationFormatter.TypedMessageParts . .ctor(对象实例,MessageDescription描述)

在System.ServiceModel.Dispatcher.OperationFormatter

。SerializeRequest(MessageVersion MessageVersion, Object[] parameters)

System.ServiceModel.Dispatcher.ProxyOperationRuntime.BeforeRequest (ProxyRpc&rpc)

在System.ServiceModel.Channels.ServiceChannel

。PrepareCall(ProxyOperationRuntime操作,Boolean单向,ProxyRpc&rpc)

在System.ServiceModel.Channels.ServiceChannel

。调用(字符串动作,布尔单向,ProxyOperationRuntime)operation, Object[] in, Object[] outs, TimeSpan timeout)

在System.ServiceModel.Channels.ServiceChannelProxy

。InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime操作)

在System.ServiceModel.Channels.ServiceChannelProxy

。调用(IMessage消息)

[0]:

在System.Runtime.Remoting.Proxies.RealProxy

。HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

您可以通过堆栈跟踪来区分这两种场景:OperationFormatter。SerializeRequest/OperationFormatter。SerializeReply

  • 如果你在SerializeRequest中崩溃,你正在试图传递一个空作为一个论点。
  • 如果你在SerializeReply中崩溃,你正在尝试返回null。

我从来没有确定这是否以某种方式特定于我的绑定,所以根据你的wcf配置,你也可以有一些完全不同的东西。

相关文章: