0

I would like to query a dictionary API from my C# method. Here's the specification for what is needed:

POST /DictService/DictService.asmx/DefineInDict HTTP/1.1
Host: services.aonaware.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

dictId=string&word=string

Here's an example of what is returned but right now I don't get anything returned with my way of doing it using Unrest: http://unirest.io/net.html

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<WordDefinition xmlns="http://services.aonaware.com/webservices/">
  <Word>string</Word>
  <Definitions>
    <Definition>
      <Word>string</Word>
      <Dictionary>
        <Id>string</Id>
        <Name>string</Name>
      </Dictionary>
      <WordDefinition>string</WordDefinition>
    </Definition>
    <Definition>
      <Word>string</Word>
      <Dictionary>
        <Id>string</Id>
        <Name>string</Name>
      </Dictionary>
      <WordDefinition>string</WordDefinition>
    </Definition>
  </Definitions>
</WordDefinition>

Here's what I tried so far:

  HttpResponse<string> jsonResponse = Unirest.post("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict")
                .header("Accept", "application/xml")
                .header("Content-Type", "application/x-www-form-urlencoded")
                .field("dictId", "wn")
                .field("word", "abandon")
                .asJson<string>();

Always I am getting the error:

406 - Client browser does not accept the MIME type of the requested page.

Can someone help and suggest how I can send this post request. Maybe there's something easier than using Unirest. I am open to any simple C# solution

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 1
    Since that´s a ASMX service, it would be faster if you added a reference to it. If not, just do a HttpWebRequest. If still want to use Unirest, I havent tried it before, just try to change the ContentType. – Juan Carlos Jun 04 '16 at 15:08
  • @JuanCarlos - can you give me an example and some more details. I am open to using anything that works :-) – Alan2 Jun 04 '16 at 15:11
  • 1
    Your response Content-Type is text-xml but you accept only application-xml. Also, of course asJson is going to fail. – Federico Dipuma Jun 04 '16 at 15:13
  • @Alan https://blogs.msdn.microsoft.com/wsdevsol/2012/12/21/help-me-how-do-i-connect-to-an-asmx-web-service/ – Juan Carlos Jun 04 '16 at 15:37

1 Answers1

1

Since it is asmx, you can generate WSDL.

enter image description here

enter image description here

It will generate the following files inside Service References folder.

enter image description here

Then you can call it as

enter image description here

HelloWorld.asmx.cs

/// <summary>
/// Summary description for HelloWorld
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class HelloWorld : System.Web.Services.WebService
{

    [WebMethod]
    public string GetHelloWorld()
    {
        return "Hello World";
    }
}

FYI: asmx is a very old technology which has been deprecated. If this is a new application, you might consider looking for REST.

Win
  • 61,100
  • 13
  • 102
  • 181