Question

When my web service returns a custom object (containing only four strings, three ints and a bool) it takes several seconds (4-8seconds). When the same server sends the same information in a string it goes almost instantly.

The custom object class is defined in the same web service if that matters.

I didnt think it would make that much of a difference, or did I miss something fundamental here?

Edit: Some code, I removed some of the variables for easier reading.

Custom class defined in the web service:

public class AddressSearchResult
{
    public AddressSearchResult()
    {
        Address = String.Empty;
        Country = String.Empty;
    }

    public AddressSearchResult(string address, string country)
    {
        Address = address;
        Country = country;
    }

    public string Address { get; set; }
    public string Country { get; set; }
}

Only difference between the two WebMethods on the web service is the return statement:

WebMethod1 returning the obj

return new AddressSearchResult((string)address["address"], (string)address["country"]);

WebMethod2 returning only a string (Just to show I'm doing the same thing here)

return new AddressSearchResult((string)address["address"], (string)address["country"]).Address;

Receiving side, the console app:

AddressSearchResult result = adrSerWS.method1("example", "yehaa"); //THIS IS SLOW
string result2 = adrSerWS.method2("example", "yehaa"); //THIS IS FAST
Was it helpful?

Solution

The problem might be that the first call to your web services takes longer than subsequent calls. Try switching the order of the service method calls you make in the console app and see if method1 is still the slowest.

Why would the first call be slower? Some ideas: 1) In the console app, the first method call made may trigger some initialization in the web service proxy. This could be your own code or something in .NET. 2) You may be hitting the web service after IIS was idle for a while and thus it is having to spawn a new worker process. 3) If you're running the console app with an attached debugger then note that this can exaggerate performance for the worst. Try running without the debugger.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top