views:

70

answers:

2

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

I stepped through the method that I called from my web service reference. I stepped through it actually right into the .asmx and back. It's definitely returning a valid complext object of type ServiceAuthResponse. Here is my .asmx method shell (I've removed all the logic for posting simplicity...just see that it returns ServiceAuthRequest as the type here):

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

I can even mouse over the debitResponse var and see the object's properties and all just as always...so the object is definitely not null...it's got state when it's being returned during my debugging.

I'm calling this service method in a codebehind of an .aspx page in another web project that's referencing/using this web service.

Here you can see a couple shots of the web service in VS:

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

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

So in one of my methods in my code-behind I try to call and grab the return object. At the top of my code-behind I have this using statement to specify that the ServiceAuthResponse should come from the proxy class (because otherwise it would conflict with some other references I've added to this web project that contain this class):

using ServiceAuthResponse = WebServicesTesting.LitleService.ServiceAuthResponse;

No here's the problem. I don't know how quite to grab the return object successfully that IssueDebit is returning. The call to IssueDebit works and when I move past the debug point set to debitResponse = litleService.IssueDebit(...); and try to view the debitResponse, I get nothing. I can't see anything in that object.

All I see is this: http://www.elbalazo.net/post/objectempty.jpg meaning the variable debitResponse should have valid state but when I mouse over I get nothing but the namespace.

Here's the code again that calls that 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 context to how I should be trying to grab and populate my variable with the complex type back coming back from the web service method call IssueDebit?

A: 

It sounds like you've got back an empty object; so to understand that we really need to see the class itself. ASMX uses XmlSerializer, which serializes public properties and fields; so as long as you have something like:

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

It should work fine. Note that it doesn't look at interface-specific members, read-only/write-only members, internal members, etc.

Trivial aside: it is fine to declare and init on the same line, but this won't impact the above (but it makes it simpler to read, IMO):

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

or (if you want) in C# 3.0:

var debitResponse = litleService.IssueDebit(...);
Marc Gravell
well I know that the method definitely is not returning an empty object so why would I get this when setting that var?
CoffeeAddict
Does that class have to be marked Serializable?
CoffeeAddict
you can see that when I debug the web method in my .asmx, the IssueDebit is returning a valid object: http://www.elbalazo.net/post/returnobject.jpg
CoffeeAddict
Still out of luck with this problem. Don't know where to go now. Tried what I could.
CoffeeAddict
So again: how are your properties / fields defined. This matters.
Marc Gravell
I had no setters on my properties. :) I did not know I needed them for the WSDL to work.
CoffeeAddict
You need them for the XML Serializer to work, and since you're using ASMX web services, you're limited to the XML Serializer.
John Saunders
A: 

The class did not have any setters in its properties. So that's why I wasn't getting any state.

So I ended up creating a wrapper class with only properties. And returning that class with those properties set by the original class.

Did not know about both above, learning more about web services all the time...this one was a headache.

CoffeeAddict
Make sure to (politely) inform your boss that he's making you learn old technologies while your company's competitors are more likely up to date.
John Saunders