Home > Software engineering >  HttpClient SyncPost returns 'Web Service method name is not valid'
HttpClient SyncPost returns 'Web Service method name is not valid'

Time:04-11

I'm absolute newby to REST API's stuff, and I try to make a POST with a XML body to a server. The server is ok (I can get some responses for a diverse GET calls), but when I try to make a POST I get 'method name is not valid'. I can't see what is wrong...

This is part of my code (C#):

string post_body = "<?xml version=\"1.0\" encoding=\"utf-8\"?> "  
                   "<mark> "  
                      $"<idMark>{idMark}</idMark> "  
                      $"<idClipLog>{idClipLog}</idClipLog> "  
                      $"<freeDescription>{freeDescription}</freeDescription> "  
                      $"<tcOut>{tcOut}</tcOut> "  
                      $"<tcIn>{tcIn}</tcIn> "  
                       "<clipLogOperator> "  
                          $"<OperatorName>{operatorName}</OperatorName>"  
                       "</clipLogOperator>"  
                       "<clipLogLayer>"  
                          $"<layerName>{layerName}</layerName>"  
                       "</clipLogLayer>"  
                       "<markKeyword>"  
                          $"<idMark>{idMKMark}</idMark>"  
                          $"<idMarkKeyword>{idMarkKeyword}</idMarkKeyword>"  
                          $"<keyword>{keyword}</keyword>"  
                       "</markKeyword>"  
                    "</mark>";


var httpContent = new StringContent(post_body);
var requestUri = $"VideoTags.asmx/CreateMark";
var response = _httpClient.PostAsync(requestUri, httpContent).Result;
if (!response.IsSuccessStatusCode)
{
    var xmldata = response.Content.ReadAsStringAsync();
    var xmlSerializer = new XmlSerializer(typeof(cExtendedSessionsResult));
    using (StringReader reader = new StringReader(xmldata.Result))
    {
        try
        {
            var logIdResp = (cExtendedSessionsResult)xmlSerializer.Deserialize(reader);
        }
        catch
        {
            throw new Exception($"[E04071035] Error in CreateMark [{_server}]");
        }
    }
}

Perhaps a problem with the body content? I need pass the XML in the POST body. I create StringContent from my XML and pass to PostAsync call. This is correct?

HttpClient seems have the correct BaseAddress (as I said before, I was able to call some get functions).

Thanks in advance!

CodePudding user response:

Thanks a lot for everybody! Finally I can talk with the provider, and seems that is an error in the specification of the API interface.

Thank you again!

  • Related