Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...

AspDotNetStorefront
DotFeed

Trying to call local 9.5.1 WebMethod from Winform Client

I have a 9.5.1 localhost WebMethod (works from aspx test page using JQuery). When I call it from a winform app It gets {"Response status code does not indicate success: 500 (Internal Server Error)."}

Winform Calling code is:

public static async Task<int> VerifyUpdateProductImages(string isbn)
        {
            var returnInt = -1;
            var testUri = "http://localhost:52561/KboAjaxBase.asmx/VerifyUpdateProductImages";
            using (var client = new HttpClient())
            {                   
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                var ajaxCallParams = new AjaxCallParams(Constants.VerifyUpdateProductImages, "none", null);
                var json = JsonConvert.SerializeObject(ajaxCallParams);
                using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
                {     
                    using (var response = await client
                        .GetAsync(testUri)
                        .ConfigureAwait(false))
                    {
                        response.EnsureSuccessStatusCode();

                        if (response.IsSuccessStatusCode)
                        {
                            var returnValue = await response.Content.ReadAsStringAsync();
                            int.TryParse(returnValue, out returnInt);
                        }
                    }
                }
                return returnInt;
            }
        }
    }



WebMethod is:

 

[WebMethod]
public AjaxCallParams VerifyStoreImagesOnServer(AjaxCallParams ajaxCallParams)
{
    int imagesCreated = -1; 
    AjaxCallParams returnParams = new AjaxCallParams(ajaxCallParams.Request, "",null);
    string isbn = ajaxCallParams.Data.ToString();
    StaticState.SetIsWebApi();
    using (var db = new DataAccess())
    {
        var productId = db.GetProductIdForSku(isbn);
        if (productId != 0)
        {
            imagesCreated = ImageFuncsServer.VerifyStoreImagesOnServer(isbn);
        }
        returnParams.Data = imagesCreated.ToString();
    }
    return returnParams;
}

 

asked Apr 28 in General by AbbottF (380 points)

1 Answer

0 votes
To start with are we talking about a .aspx page or a .asmx service? Cause it looks like you are using a web service with the client code.

As for the error with the webservice without knowing about how AjaxCallParams and StaticState are setup code wise it is a bit hard for me to say. Cause without knowing the rest of the code it confusing as to why the isbn just not a string paramater in the service method to begin with. Either way it looks like you need to be running a debugger in visual studio on the website. That way you can see were you are getting the 500 response from.
answered Apr 29 by mmcgeachy (5,025 points)
...