C#将数据发送到soap服务器并接收数据。

时间:2016-10-06 01:54:49

标签: c# web-services soap

美好的一天我想将肥皂数据发送到肥皂服务器并从中收到回复 我有以下代码段。不幸的是,它显示了" System.Xml.XmlException:' soap'是一个未声明的前缀。"当我点击一个按钮。这是片段

    /// <summary>
    /// Execute a Soap WebService call
    /// </summary>
    public string ConvertHexString(string HexString , string Uri)
    {
        HttpWebRequest request = CreateWebRequest(Uri);
        XmlDocument soapEnvelopeXml = new XmlDocument();
        String S = @"<?xml version='1.0' encoding='utf-8'?> \
                        <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xlmns:xsd='http://www.w3.org/2001/XMLSchema' xlmns:soap='http://schemas.xlmsoap.org/soap/envelope/'>   \
                            <soap:Body> \
                                     \
                                    <proxcard>";
        S += HexString; 
        S+=@"          </proxcard> \
                   </ProximityNo> \
                </soap:Body> \
             </soap:envelope>";
            soapEnvelopeXml.LoadXml(S.Substring(S.IndexOf(Environment.NewLine)));



        using (Stream stream = request.GetRequestStream())
        {
            soapEnvelopeXml.Save(stream);
        }

        using (WebResponse response = request.GetResponse())
        {
            using (StreamReader rd = new StreamReader(response.GetResponseStream()))
            {
                string soapResult = rd.ReadToEnd();
                return soapResult;
            }
        }
    }
    /// <summary>
    /// Create a soap webrequest to [Url]
    /// </summary>
    /// <returns></returns>
      HttpWebRequest CreateWebRequest(string Uri)
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Uri);
        webRequest.Headers.Add(@"SOAP:Action");
        webRequest.ContentType = "text/xml;charset=\"utf-8\"";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;
    }



}

}

        string HexString = "1AF3A139";
        string Uri="http://192.168.8.11/ADLINXTRAK/ProximityWebService.php";
        string xmlstring = ConvertHexString(HexString,Uri);
        Console.WriteLine(xmlstring);

最后4行是按钮点击事件,非常感谢您的回复。

0 个答案:

没有答案