Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:38:17+00:00 2026-06-15T01:38:17+00:00

I have API where I need to send request in XML format to get

  • 0

I have API where I need to send request in XML format to get response (in XML too). I think this is called SOAP API but I am not sure so I insert here exectly what I send.

Request should look like this:

<request>
    <login>name</login>
    <password>password</password>
    <hotId>1</hotId>
</request>

And I should send it to this url to get response: https://api.xxx.com/v1/hotel/get

This is how to use this with php and curl:

<?php
$login    = '*****';
$password = '*****';

$request =
'<?xml version="1.0"?>' . "\n" .
'<request>' .
    '<login>' . htmlspecialchars($login) . '</login>' .
    '<password>' . htmlspecialchars($password) . '</password>' .
    '<hotId>1</hotId>' .
'</request>';

$ch = curl_init('https://api.xxx.com/x1/hotel/get');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

echo "<pre>\n";
echo htmlspecialchars($response);
echo "</pre>";

So what’s the best way how to do this in C#?

I tried something like this but It´s not working and I think there must be better way.

    System.Net.WebRequest req = System.Net.WebRequest.Create(@"https://api.xxx.com/v1/hotel/get");

    req.ContentType = "text/xml";
    req.Method = "POST";

    byte[] bytes = System.Text.Encoding.ASCII.GetBytes("<?xml version=\"1.0\"?><request><login>login</login><password>pass</password><hotId>1</hotId></request>");
    req.ContentLength = bytes.Length;
    Stream os = req.GetRequestStream();
    os.Write(bytes, 0, bytes.Length);


    System.Net.WebResponse resp = req.GetResponse();
    if (resp == null) return;
    System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());

    string responsecontent = sr.ReadToEnd().Trim();

Edit:
Get method generated with wsdl.exe. I am missing here login and password params to new object[] but don´t know how to add them.

[System.Web.Services.Protocols.SoapRpcMethodAttribute("http://api.xxx.com/v1/hotel/get", RequestNamespace="http://api.xxx.com/v1/hotel/", ResponseNamespace="http://api.xxx.com/v1/hotel/", Use=System.Web.Services.Description.SoapBindingUse.Literal)]
[return: System.Xml.Serialization.XmlElementAttribute("hotel")]
public hotelType get(int hotId) {
    object[] results = this.Invoke("get", new object[] {
                hotId});
    return ((hotelType)(results[0]));
}

Constructor:

public HotelService() {
    this.Url = "http://api.xxx.com/v1/hotel/";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:38:19+00:00Added an answer on June 15, 2026 at 1:38 am

    The mode of communication you describe is a SOAP service.

    In .NET, the easiest way to consume one of these services is to have the WSDL (Web Service Definition Language) file. This file contains the metadata regarding the exposed web service: where it is, what methods are available, what data types are produced and accepted by the methods, what transport and/or security layers should be used, etc.

    You should be able to get the WSDL from the web service provider; you can either download it or reference it from its hosted location. Once you have this file or know its location, all you have to do is go into VS, right-click on the project containing the code that needs to use the web service, and click “Add Service Reference…”. Then type in the location of the WSDL (this is designed to look for hosted WSDL files, not ones you’ve hosted, but it will work both ways) and you should see the information about the service. Click OK, and VS will auto-generate a proxy class and any custom data types needed, which when called will form and transmit the proper SOAP message and wait for the response.

    Then, you just new up an instance of the service and work with it like any class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send a request to an API that only accepts XML. I've
I need to send a http request without encoding (I have to consume a
I have to deal with an API which need to be provided a DataSource
I have a maven project that contains a certain api I need to use
I have a processes where I need to make ~100 http api calls to
I have an ASP.NET Web API (version 4) REST service where I need to
I need to check if i have used any private API s in my
I have a RestFull grails api that i expose through grails Controller. I need
I have a page where I need SWFObject, jQuery and Google Maps API. I
I need to test some api. For example I have multiple @Test methods in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.