开发者

C# webservice losing data on return

开发者 https://www.devze.com 2022-12-14 02:47 出处:网络
I am programming a client program that calls a webmethod but when I get the return data there aremissing values on some of the fields and objects.

I am programming a client program that calls a webmethod but when I get the return data there are missing values on some of the fields and objects.

The webmethod in turn is calling a WCF method and in the WCF method the return data is fine. But when it is passing to the webservice the return data is missing.

Is there any way to fix this problem?


This is my client code calling the webservice:

    ReLocationDoc query = new ReLocationDoc();

    query.PerformerSiteId = 1;
    query.PerformerUserId = 1;
    query.FromStatus = 10;
    query.ToStatus = 200;

    ReLocationDoc doc = new ReLocationDoc();

    ServiceReference1.QPSoapClient service = new QPSoapClient();
    try {
        service.GetRelocationAssignment(query, out doc);

        string test = doc.Assignment.Id.ToString();

    } catch(Exception ex) {

        MessageBox.Show(ex.Message);
    }

The webmethod code is here:

        [WebMethod]
        return m_reLocationClient.GetRelocationAssignment(query, out reLocationDoc);
    }

And at last the WCF code:

    public ReLocationResult GetRelocationAssignment(ReLocationDoc query, out ReLocationDoc reLocationDoc) {
        try {
            LOGGER.Trace("Enter GetRelocationAssignment().");

            ReLocationResult result = reLocationCompactServiceClient.GetRelocationAssignment(out reLocationDoc, query);

            if(reLocationDoc.Assignment == null || reLocationDoc.Assignment.CurrentStatus == STATUS_FINISHED) {
                ReLocationDoc newQuery = new ReLocationDoc();
                newQuery.Assignment = new AssignmentDoc();
                newQuery.Assignment.EAN = DateTime.Today.ToString();
                newQuery.PerformerSiteId = QPSITE;
                newQuery.PerformerUserId = QPUSER;
                reLocationDoc.AssignmentStatus = m_settings.ReadyStatus; ;
                result = reLocationCompactServiceClient.CreateReLocationAssignment(out reLocationDoc, newQuery);
            }

            return result;

        } finally {
            LOGGER.Trace("Exit GetRelocationAssignment().");
        }
    }

The GetRelocationAssignment:

    public ReLocationResult GetRelocationAssignment(ReLocationDoc query, out ReLocationDoc reLocationDoc) {
        try {
            LOGGER.Trace("Enter GetRelocationAssignment().");

            ReLocationDoc doc = new ReLocationDoc();
            ReLocationResult result = new ReLocationResult();

            new Database(Connection).Execute(delegate(DBDataContext db) {

                User user = GetVerifiedUser(db, query, MODULE_ID);
                SiteModule siteModule = SiteModule.Get(db, query.PerformerSiteId, MODULE_ID);

                Status status = Status.Get(db, query.FromStatus, query.ToStatus, 0);
                Status startStatus = Status.Get(db, query.FromStatus, 0);
                Status endStatus = Status.Get(db, query.ToStatus, 0);

                IQueryable<Assignment> assignments = Assignment.GetAssignmentsWithEndStatus(db, siteModule, endStatus);
                assignments = Assignment.FilterAssignmentStartStatus(assignments, startStatus);

                foreach(Assignment assignment in assignments) {

                    LOGGER.Debug("Handling assignment: " + assignment.Id);

                    result.Status = true;
                    AssignmentDoc assignmentDoc = FillAssignmentDoc(assignment);
                    //ReLocationDoc doc = new ReLocationDoc();

                    AssignmentStatus sts = assignment.AssignmentStatus.OrderByDescending(ass => ass.Id).First();
                    assignmentDoc.CurrentStatus = sts.Status.Zone;

                    Status currentStatus = sts.Status;

                    IList<Item> items = assignment.Items.ToList();
                    IList<ItemDoc> itemDocs = new List<ItemDoc>();
                    foreach(Item item in items) {

                        ItemDoc itemDoc = FillItemDoc(item);

                        ItemDetail itemDetail;
                        if(ItemDetail.TryGet(db, item.Id, out itemDetail)) {
                            ItemDetailDoc itemDetailDoc = FillItemDetailDoc(itemDetail);
                            itemDoc.Details = new ItemDetailDoc[1];


                            Event eEven开发者_运维技巧t = null;
                            if(Event.GetEvent(db, itemDetail, currentStatus, out eEvent)) {
                                EventDoc eventDoc = FillEventDoc(eEvent);
                                itemDetailDoc.Events = new EventDoc[1];

                                if(eEvent.LocationId.HasValue) {
                                    Location location = null;
                                    if(Location.TryGet(db, eEvent.LocationId.Value, out location)) {
                                        eventDoc.Location = new LocationDoc();
                                        eventDoc.Location = FillLocationDoc(location, db);
                                    }
                                }
                                itemDetailDoc.Events[0] = eventDoc;
                            }
                            itemDoc.Details[0] = itemDetailDoc;
                        }
                        itemDocs.Add(itemDoc);
                    }
                    assignmentDoc.Items = itemDocs.ToArray();
                    doc.Assignment = assignmentDoc;
                }

            }, delegate(Exception e) {
                result.Message = e.Message;
            });

            reLocationDoc = doc;
            return result;

        } finally {
            LOGGER.Trace("Exit GetRelocationAssignment().");
        }
    }

In all this code the return data is fine. It is loosing data only when passing to the webmetod.

Enter code here.


Also, the ordering of the XML tags in the message makes difference - I had a similar problem about maybe two years ago, and in that case parameter values were dissappearing during transmission because the sending part ordered the tags differently than what was defined in the schema.


Make surethe XML tags are being accessed with the same casing at either end. if the casing is not the same then the value won't be read.


You should check it all message are sending back from your webservice. Call your webservice manually and check its response.

  • If all data is there, probably your webservice reference is outdated; update it by right-clicking your webservice reference and choose "Update"
  • If your data don't came back, your problem is probably related to webservice code. You should check your serialization code (if any) again, and make sure all returned types are [Serializable]. You should check if all return types are public as it's mandatory for serialization.

As noted per John Saunders, [Serializable] isn't used by XmlSerializer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号