locked
Window c# WebApi call issue RRS feed

  • Question

  • User952455838 posted

    I have a test class for an asp.net WebService asmx function. When I attempt to make the call I get:

    "Method System.Net.Http.CloneableExtensions.Clone: type argument 'System.Net.Http.Headers.MediaTypeHeaderValue' violates the constraint of type parameter 'T'."

    Any suggestions?

    Thanks

    Abbott

    The calling routine is ...

    public static int VerifyImages(string isbn)
            {
                var count = -5;
                var ajaxCallParams = new AjaxCallParams( );
                var apiImageUri = "https://www.????.com//KboAjaxImages.asmx";
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(apiImageUri);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = client.PutAsJsonAsync("VerifyStoreImagesOnServer", ajaxCallParams).GetAwaiter().GetResult();
                    if (response.IsSuccessStatusCode)
                    {
                        // Get the URI of the created resource.  
                        var content = response.Content.ReadAsStringAsync().ToString();
                        ajaxCallParams = (AjaxCallParams)JsonConvert.DeserializeObject(content);
                        count = (int)ajaxCallParams.Data;
                    }
                }
                       
                return count;
            }
            

    The service is;

    public partial class KboAjaxBase : System.Web.Services.WebService
    {    [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())
            {
                imagesCreated = ImageFuncsServer.VerifyStoreImagesOnServer(isbn);
            }
            returnParams.Data = imagesCreated.ToString();
           return returnParams;
        }
        
    }

    Friday, May 21, 2021 5:32 PM

All replies