Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send a soap request but getting an error on webresponse.
The remote server returned an error: (404) Not Found.
I have tested the xml in SOAPUI and it is giving a valid response there.
what could be the reason .
Please help

XML
string soap =
                        @"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
<s:Header>
<AuthHeader xmlns=""http://stellatravelgateway.stellatravelservices.co.uk"">119d8a82-0d5b-4893-****-************</AuthHeader>
</s:Header><s:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<Search xmlns=""http://stellatravelgateway.stellatravelservices.co.uk/AirService"">
<request SearchType=""Availability"" FlexiDays=""0"" FareType=""All"" SearchSource=""Default"" ReturnIncompleteResults=""false"" SortOrder=""Price"" ChildPaxCount=""1"" AdultPaxCount=""1"" DirectFlightsOnly=""false"" CabinClass=""All"" InfantWithSeatPaxCount=""0"" InfantPaxCount=""1"">
                         <SelectedAirlines><string>BA</string></SelectedAirlines>
            <MaximumConnectionTimeMins xsi:nil=""true""/><MaxResultsPerAirline xsi:nil=""true""/>
                <JourneyDetails>
<JourneyDetail DepartureDateTime=""2014-09-01T00:00:00"" DeparturePoint=""lon"" DeparturePointIsCity=""false"" DestinationPoint=""bcn"" DestinationPointIsCity=""false"" ViaPointAirportCode=""/>
                    <JourneyDetail DepartureDateTime=""2014-09-08T00:00:00"" DeparturePoint=""bcn"" DeparturePointIsCity=""false"" DestinationPoint=""lon"" DestinationPointIsCity=""false"" ViaPointAirportCode=""/>
                        </JourneyDetails>
            <MaxResults xsi:nil=""true""/>
                <IncludePriorDepartues>false</IncludePriorDepartues>
            <SessionID>c80b7581-28b8-4b04-829f-d9a3e79b5614</SessionID>
                </request>
                </Search>
                </s:Body>
                    </s:Envelope>

";

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://stellatravelgateway.stellatravelservices.co.uk/AirService");
        req.Headers.Add("SOAPAction", "http://stellatravelgateway.stellatravelservices.co.uk/AirService/IAirService/Search");
        req.ContentType = "text/xml;charset=utf-8";
        req.Accept = "text/xml";
        req.Method = "POST";

        using (Stream stm = req.GetRequestStream())
        {
            using (StreamWriter stmw = new StreamWriter(stm))
            {
                stmw.Write(soap);
            }
        }

        WebResponse response = req.GetResponse();

        Stream responseStream = response.GetResponseStream();
        // TODO: Do whatever you need with the response
.
Posted

1 solution

[new solution]
add web service reference with the given address. then use the following code instead of xml.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Test_WebSvc
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ServiceReference1.AirServiceClient cl = 
                    new ServiceReference1.AirServiceClient();
                /*
                you need credentials
                cl.ClientCredentials.UserName
                */
                cl.Open();

                cl.Search(new ServiceReference1.AirSearch()
                {
                    SelectedAirlines = new String[] { "BA" }
                });
                cl.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
 
Share this answer
 
v2
Comments
hrishisinha 12-Feb-14 9:23am    
sir but if i use this xml in SOAPUI i get a valid response.
so what should i code to get in my c# also.
Vedat Ozan Oner 12-Feb-14 10:50am    
no way. it is not related to xml, the address for webrequest matters. I think the address that you use in SoapUI is different from the one in the code. I'll also try with SoapUI.
Vedat Ozan Oner 12-Feb-14 11:00am    
SoapUI also fails
hrishisinha 12-Feb-14 11:03am    
sir the address in soapui is
http://devapi.stellatravelgateway.stellatravelservices.co.uk/AirService.svc

and i have also edited my code with this link but its not helping
Vedat Ozan Oner 12-Feb-14 11:23am    
'it's not helping' but what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900