WebService 之 Restful Tool
透過WebService 傳送一個XML的Request,來獲取XML的Response
如何將 XSD 檔案轉化為類檔案呢?
XSD /classes filename.xsd
private static bool RemoteCertValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
{
// TODO: validate server cert
return true;
}
{
// TODO: validate server cert
return true;
}
private void button1_Click(object sender, EventArgs e)
{
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(RemoteCertValidate);
{
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(RemoteCertValidate);
// setup request
WebServiceRequest request = new WebServiceRequest();
WebServiceRequest request = new WebServiceRequest();
XmlSerializer s = new XmlSerializer(typeof(WebServiceRequest));
MemoryStream ms = new MemoryStream();
XmlTextWriter xmlWriter = new XmlTextWriter(ms, Encoding.UTF8);
s.Serialize(xmlWriter, request);
String requestXml = Encoding.UTF8.GetString(ms.ToArray());
MemoryStream ms = new MemoryStream();
XmlTextWriter xmlWriter = new XmlTextWriter(ms, Encoding.UTF8);
s.Serialize(xmlWriter, request);
String requestXml = Encoding.UTF8.GetString(ms.ToArray());
// send request
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(WebService_Http_URL);
X509Certificate2 certPfx = new X509Certificate2();
certPfx.Import("Certificate.pfx", "", X509KeyStorageFlags.PersistKeySet);
req.ClientCertificates.Add(certPfx);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(WebService_Http_URL);
X509Certificate2 certPfx = new X509Certificate2();
certPfx.Import("Certificate.pfx", "", X509KeyStorageFlags.PersistKeySet);
req.ClientCertificates.Add(certPfx);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] requestXmlBytes = Encoding.UTF8.GetBytes(requestXml);
req.ContentLength = requestXmlBytes.Length;
Stream postStream = req.GetRequestStream();
postStream.Write(requestXmlBytes, 0, requestXmlBytes.Length);
postStream.Flush();
postStream.Close();
req.ContentLength = requestXmlBytes.Length;
Stream postStream = req.GetRequestStream();
postStream.Write(requestXmlBytes, 0, requestXmlBytes.Length);
postStream.Flush();
postStream.Close();
// get and unmarshal response
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
StreamReader sr = new StreamReader(respStream, Encoding.UTF8);
string responseXml = sr.ReadToEnd();
s = new XmlSerializer(typeof(WebServiceResponse));
WebServiceResponse respObj = (WebServiceResponse)s.Deserialize(new StringReader(responseXml));
Stream respStream = resp.GetResponseStream();
StreamReader sr = new StreamReader(respStream, Encoding.UTF8);
string responseXml = sr.ReadToEnd();
s = new XmlSerializer(typeof(WebServiceResponse));
WebServiceResponse respObj = (WebServiceResponse)s.Deserialize(new StringReader(responseXml));
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20200170/viewspace-742088/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Restful是什麼,SOAP Webservice和RESTful WebserviceRESTWeb
- webservice和restful的區別WebREST
- springmvc+mybatis+restful+webservice+dubboSpringMVCMyBatisRESTWeb
- # JAVA RESTful WebService實戰筆記(一)JavaRESTWeb筆記
- springmvc+mybatis+restful+webservice 分散式架構SpringMVCMyBatisRESTWeb分散式架構
- springmvc+mybatis+restful+webservice 微服務架構SpringMVCMyBatisRESTWeb微服務架構
- restful+springmvc+mybatis+ webservice 分散式架構RESTSpringMVCMyBatisWeb分散式架構
- 使用CXF與Spring整合實現RESTFul WebServiceSpringRESTWeb
- springmvc+mybatis+restful+webservice Jeesz分散式架構SpringMVCMyBatisRESTWeb分散式架構
- 基於 Spring Boot 2.0 構建一個 RESTful WebServiceSpring BootRESTWeb
- springmvc+mybatis+restful+shiro+Dubbo+webservice 分散式架構SpringMVCMyBatisRESTWeb分散式架構
- WebService之超級HelloWorldWeb
- k8s APIServer依賴的go-restful WebService框架的簡單使用K8SAPIServerGoRESTWeb框架
- 架構之:REST和RESTful架構REST
- RestFul Api 設計 之 URLRESTAPI
- WebService之Spring+CXF整合示例WebSpring
- Android開發之WebService介紹AndroidWeb
- 通過rul讀取流資料此條適用於 webservice-restful 執行介面WebREST
- WCF、WebAPI、WCFREST、WebService之間的區別WebAPIREST
- Yii2.0 RESTful API 之版本控制RESTAPI
- Yii2.0 RESTful API 之速率限制RESTAPI
- go tool pprofGo
- 常用sqltun toolSQL
- Tool-Navicat
- Tool-PostgresqlSQL
- Office Tool Plus
- 10-django——RESTful API 之序列化DjangoRESTAPI
- Flask_restful 之 自定義錯誤資訊FlaskREST
- golang restful 框架之 go-swaggerGolangREST框架Swagger
- 【原創】WebService大講堂之Axis2(3):使用services.xml檔案釋出WebServiceWebXML
- webservice介面Web
- WebService基本Web
- soa == webServiceWeb
- 求助webserviceWeb
- WebService求助Web
- webservice testWeb
- Spring Tool SuiteSpringUI
- mysql user qutoa toolMySql