How to send SOAP request to WCF service?

Can someone point me to an example how to send a SOAP WCF Request Serve and return a SOAP response? Typically, the Travel client sends a SOAP request with the search parameters and WCF Service in the database, and then sends the appropriate holidays.

I continue to get this error using the method I used: "The remote server returned an error: (400)" Bad request "

0
source share
4 answers

You received an error because the server does not understand the HTTP request. This may be the binding you configured, or the service proxy is incorrect at the client level.

, , HTTP GET, HTTP POST. HTTP- [WebGet] . , [WebGet] .

+1

, , .

, , WCF IIS. , .svc ISAPI ASP.NET.

0

SoapUI WcfTestClient, Visual Studio (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE).

WCF / SOAP.

, svcutil.exe:

svcutil.exe  (service URL)

*.cs *.config, .

0

, . , WCF , .

, HTTP- WCF. .

HTTP-, , HTTP-, - " : (400)

, :

        // Get the response. 
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;

:

 private void CreateMessage()
    {
        // Create a request using a URL that can receive a post. 
        WebRequest request = WebRequest.Create("http://www.XXXX.com/Feeds");
        string postData = "<airport>Heathrow</airport>"; 

//           request.Method = "POST";

        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        request.ContentType = "application/soap+xml; charset=utf-8";
        request.ContentLength = byteArray.Length;

        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        // Get the response. 
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;

        // Display the status. 
        HttpContext.Current.Response.Write(((HttpWebResponse)response).StatusDescription);

        // Get the stream containing content returned by the server. 
        dataStream = response.GetResponseStream();

        // Open the stream using a StreamReader for easy access. 
        StreamReader reader = new StreamReader(dataStream);

        // Read the content. 
        string responseFromServer = reader.ReadToEnd();

        // Display the content. 
        HttpContext.Current.Response.Write(responseFromServer);

        // Clean up the streams. 
        reader.Close();
        dataStream.Close();
        response.Close(); 

    }

0

All Articles