views:

264

answers:

3

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 eEvent = 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.

+1  A: 

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.

ck
Do you mean the XML files under the webreference?
Tan
no, xml returned by your service. its returns a string which contains a XML?
Rubens Farias
No its the same casting on both ends.
Tan
What client type are you building (asp.net, winforms?) Can you post the code used to call the webservice as an edit to your question?
ck
iam building a winform.
Tan
Thanks for the update, can you post this method: `service.GetRelocationAssignment(query, out doc);`
ck
A: 

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.

Anders Fjeldstad
...and WCF was used on the server side to define the web service.
Anders Fjeldstad
Yes wcf is used to define the webservice. How did you solve the problem?
Tan
In our case, the error was resolved by having the caller/client change its implementation to honor the order of message elements (XML tags) as defined in the WCF service schema.
Anders Fjeldstad
+1  A: 

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.

Rubens Farias
my webmethod is only like this [WebMethod] public ReLocationResult GetItemInfo(ReLocationDoc query, out ReLocationDoc reLocationDoc) { return m_reLocationClient.GetItemInfo(query, out reLocationDoc); }when iam debugging in the wcf all return data is fine. when it is returning to the webmethod. Data is missing.
Tan
@Tan, so probably some type isn't marked as `[Serializable]`; For testing proposes, try to serialize it manually, by using XmlSerializer class
Rubens Farias
+1 for the serializable check
ck
`[Seria;izable]` is not used bt XML Seria;ization.
John Saunders
@John, shame on me; can you please check my information again?
Rubens Farias