1

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!

  • Unrelated: You should really `await` async calls. But that's probably not what's causing your issue. – Fildor Apr 07 '22 at 13:06
  • Maybe you can check if `VideoTags.asmx/CreateMark` allows PUT instead of POST? Would be surprising to me, since I'd expect a POST for an Endpoint called "CreateXXX", but who knows? – Fildor Apr 07 '22 at 13:08
  • A GET/POST is the data that goes into the body of a http message and is optional. A http consists of a URL (with optional parameters, http headers, a body (which may contain multiple parts). There are 5 steps that occurs 1) Client sends request using POST 2) Server receives request with GET 3) Server processes the request 4) Server sends response with POST 5) Client receives the response with GET. Make sure your GET/POST are in the correct locations in your code. – jdweng Apr 07 '22 at 13:13
  • This looks like SOAP, so you might be missing the relevant HTTP request headers that need to be set to tell the service which action you want to perform. – Martin Costello Apr 07 '22 at 13:15
  • @MartinCostello OP explicitly mentions "REST" - maybe he's wrong in that? Are you suggesting this? – Fildor Apr 07 '22 at 13:19
  • 1
    Or, it could be that the action you're asking it to perform doesn't have that name: https://stackoverflow.com/questions/11878064/web-service-method-name-is-not-valid – Martin Costello Apr 07 '22 at 13:20
  • @Fildor ASMX was generally used to implement SOAP-based services in .NET Framework which you'd then consume with code generated by `wsdl.exe` that would set all the headers etc. They're more fiddly to implement with a vanilla `HttpClient` in a more modern stack than something that's a simple "REST API" that's just GETs and PUTs with URLs. – Martin Costello Apr 07 '22 at 13:22
  • 1
    @MartinCostello Now I remeber, yes. We abandoned WCF some years ago, now come the flashbacks ... – Fildor Apr 07 '22 at 13:27

1 Answers1

0

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!