1. 程式人生 > >c#呼叫引數是xml的外部介面(wsdl)

c#呼叫引數是xml的外部介面(wsdl)

 string url = "http://xxxx/service/XChangeServlet?account=00004&groupcode=001";
            XDocument document = XDocument.Load(@"E:\新建資料夾\NCSCXML\CESHI.xml");
            string xmlFileName = document.ToString();
            //第一步---構建HttpWebRequest
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
            WebReq.ContentType = "text/xml";
            WebReq.Method = "POST";
            //第二步--寫入引數
            //WebReq.ContentLength = Encoding.UTF8.GetByteCount(xmlFileName);
            using (StreamWriter requestW = new StreamWriter(WebReq.GetRequestStream()))
            {
                requestW.Write(xmlFileName);
            }
            //第三步--獲取返回的結果
            string backstr = null;
            using (HttpWebResponse response = (HttpWebResponse)WebReq.GetResponse())
            {
                StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
                backstr = sr.ReadToEnd();
            }
            return backstr;
        }