没有得到SOAP响应

时间:2014-11-03 12:34:59

标签: c# soap

我的SOAP请求有效 - 点击服务器并在服务器日志中显示我的请求并发送响应,但我无法通过下面的代码(C#和ASP.NET)读取响应。我遗漏了什么?

    try
    {
        string url = "http://a.b.c.d/ABC/services/DOMFlightAvailability?wsdl";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.KeepAlive = false;
        req.ProtocolVersion = HttpVersion.Version10;
        req.Method = "POST";

        string request = "<Request>"
                  + "<Origin>BOM</Origin>"
                  + "<Destination>BLR</Destination>"
                  + "<DepartDate>2014-11-15</DepartDate>"
                  + "<ReturnDate>2014-11-15</ReturnDate>"
                  + "<AdultPax>1</AdultPax>"
                  + "<ChildPax>1</ChildPax>"
                  + "<InfantPax>1</InfantPax>"
                  + "<Currency>INR</Currency>"
                  + "<Clientid>123</Clientid>"
                  + "<Clientpassword>123</Clientpassword>"
                  + "<Clienttype>123</Clienttype>"
                  + "<Preferredclass>E</Preferredclass>"
                  + "<mode>ONE</mode>"
                  + "<PreferredAirline>AI,G8,IC,6E,9W,S2,IT,9H,I7,SG</PreferredAirline>"
              + "</Request>";           

        byte[] postBytes = Encoding.ASCII.GetBytes("xmlRequest=" + request + "");
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = postBytes.Length;
        Stream requestStream = req.GetRequestStream();
        requestStream.Write(postBytes, 0, postBytes.Length);
        requestStream.Close();
        HttpWebResponse response = (HttpWebResponse)req.GetResponse();
        Stream resStream = response.GetResponseStream();
        var sr = new StreamReader(response.GetResponseStream());
        string responseText = sr.ReadToEnd();
        Response.Write(responseText);
        lblResult.Text = responseText;
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }

这是我的另一种方式 - 点击服务器并传输响应,但我仍然无法获得响应数据

    try
    {

        DOMFlightAvailabilityPortTypeClient obj = new DOMFlightAvailabilityPortTypeClient();
        string req = "<Request>"
                + "<Origin>BOM</Origin>"
                + "<Destination>DEL</Destination>"
                + "<DepartDate>2014-11-20</DepartDate>"
                + "<ReturnDate>2014-12-21</ReturnDate>"
                + "<AdultPax>1</AdultPax>"
                + "<ChildPax>0</ChildPax>"
                + "<InfantPax>0</InfantPax>"
                + "<Currency>INR</Currency>"
                + "<Clientid>123</Clientid>"
                + "<Clientpassword>123</Clientpassword>"
                + "<Clienttype>123</Clienttype>"
                + "<Preferredclass>E</Preferredclass>"
                + "<mode>ONE</mode>"
                + "<PreferredAirline>AI,G8,IC,6E,9W,S2,IT,9H,I7,SG</PreferredAirline>"
            + "</Request>";

        string str = obj.getAvailability(req);
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(str);
        DataSet ds = new DataSet();
        ds.ReadXml(new XmlTextReader(new StringReader(str)));
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();


    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }

0 个答案:

没有答案