Problems with returning a returned complex object from a service method call

(No, this is not the same as my last post, I am trying to do something different here as in var type)

I went through a method I called from my web service link. I went through this straight to .asmx and back. It definitely returns a valid add-on object of type ServiceAuthResponse. Here is my wrapper for the .asmx method (I've removed all the logic for ease of posting ... just see that it returns ServiceAuthRequest as a type here):

public ServiceAuthResponse IssueDebit(...)
{
    ....
    return debitResponse;
}

      

I can even hover over the debitResponse var and see the properties of the object and everything is the same as always ... so the object is definitely not null ... it got the state when it returned during my debugging.

I am calling this service method in the codebehind of the .aspx page in another web project that is referencing / using this web service.

You can see a couple of snapshots of the web service in VS here:

http://www.elbalazo.net/post/webservicespic1.jpg

http://www.elbalazo.net/post/webservicespic2.jpg

So, in one of my methods in my code, I am trying to call and capture the returned object. At the top of my code, I have this using statement to indicate that the ServiceAuthResponse should come from a proxy class (as it would otherwise contradict some of the other links I added to this web project that contains this class):

using ServiceAuthResponse = WebServicesTesting.LitleService.ServiceAuthResponse;

      

There is no problem here. I don't know how to grab the return object returned by the IssueDebit successfully enough. The IssueDebit call works and when I go after the debug point set in debitResponse = litleService.IssueDebit (...); and try to view debitResponse, I get nothing. I don't see anything in this object.

All I can see is this: http://www.elbalazo.net/post/objectempty.jpg which means the debitResponse variable should have the correct state, but when I click on it I get nothing but the Namespace ...

Here's again the code that calls this IssueDebit web service method:

private void IssueDebit()
{
    ValidateFormData();
    SetState();

    if (string.IsNullOrEmpty(txtDebitAmount.Text))
        throw new NullReferenceException("Debit amount is empty");

   ServiceAuthResponse debitResponse;

    debitResponse = litleService.IssueDebit(...);

    pnlIssueDebitResults.Visible = true;

    SetIssueDebitResults(debitResponse);

}

      

Am I doing something wrong in the context of how I should be trying to grab and populate my variable with a complex type returning from the IssueDebit web service method method?

+2


source to share


2 answers


It looks like you returned an empty object; to understand that we really need to see the class itself. ASMX uses XmlSerializer

which serializes public properties and fields; so for now you have something like:

public class ServiceAuthResponse() {
    public int ID {get;set;}
    public string Name {get;set;}
}

      

It should work fine. Note that it does not consider interface members, read-write-only members, internal members, etc.

Trivial aside: it's okay to declare and initialize on the same line, but that won't affect the above (but it makes it easier to read, IMO):



ServiceAuthResponse debitResponse = litleService.IssueDebit(...);

      

or (if you like) in C # 3.0:

var debitResponse = litleService.IssueDebit(...);

      

0


source


The class had no settings in its properties. So I didn't get any state.

So I ended up creating a wrapper class with only properties. And return this class with the properties set by the original class.



Didn't know about all of the above, was constantly learning about web services ... it was a headache.

0


source







All Articles