ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
News
Php Tips
Android Programming
Design Pattern By PHP
Spring+Strut+Hibernate
C# Tips & Technique
C# Design Pattern
Linux Quick Tips
C# using Linq น่าใช้จริงๆ
Java & JavaScript Tips
Database & SQL
ZengCode Framework Guide
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     C# consume Oil Price จาก PTT โดยไม่ผ่าน WS Proxy ครับ  (2010-02-26)

ไม่มีการ Add Web Refference (Web Service Proxy) จะใช้ HttpRequest และ HttpResponse นะครับ

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Xml;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //com.pttplc.www.PTTInfo a = new WindowsFormsApplication1.com.pttplc.www.PTTInfo();
            //MessageBox.Show(a.GetOilPrice("thai",25,02,2553));
        }

        private void button2_Click(object sender, EventArgs e)
        {
           // String strSoapMessage = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><HelloWorld xmlns='http://tempuri.org/' /></soap:Body></soap:Envelope>";
            String strSoapMessage = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetOilPrice xmlns='http://www.pttplc.com/ptt_webservice/'><Language>string</Language><DD>26</DD><MM>02</MM><YYYY>2553</YYYY></GetOilPrice></soap:Body></soap:Envelope>";

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://www.pttplc.com/pttinfo.asmx");
            webRequest.Headers.Add("SOAPAction", "http://www.pttplc.com/ptt_webservice/GetOilPrice");
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            StreamWriter stm = new StreamWriter(webRequest.GetRequestStream(), Encoding.UTF8);
            stm.Write(strSoapMessage);
            stm.Flush();
            stm.Close();
            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            //รอจนกว่าจะตอบกลับ
            asyncResult.AsyncWaitHandle.WaitOne();
            // get the response
            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
            {
                soapResult = rd.ReadToEnd();
            }

            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(soapResult);

            XmlNodeList Result = xDoc.GetElementsByTagName("GetOilPriceResult");
            MessageBox.Show("Result: " + Result[0].InnerText);

            webBrowser1.DocumentText = soapResult;
            richTextBox1.Text = soapResult;
        }
    }
}

 


Comment

Mr.ZengCode  (02 มีนาคม 2553)   
IP : 58.137.188.243

     ไอ้แบบนี้ก็ใช้ได้ครับ ทดสอบแล้ว

 public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }


        private void button1_Click(object sender, EventArgs e)
        {

            ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);

          ..........................................................

      }

 



Mr.ZengCode  (02 มีนาคม 2553)   
IP : 58.137.188.243

//หากเรียก web service ที่ deploy บน SSL ก็แทรกคำสั่งนี้ไปนะครับ  เป็นการให้ application ของเรายอมรับ cer โดยอัตโนมัติ เพราะว่ามันไม่มี popup ให้เรายอมรับเหมือนเราเปิด browser อ่ะครับ หลังจากคำสั่งนี้แล้วจะเรียก web หรือ webservice ก็สุดแต่ใจจะไขว่คว้าเลยครับ


            ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);



Mr.ZengCode  (26 กุมภาพันธ์ 2553)   
IP : 203.144.180.65

 แทรก inline ในไฟล์ .aspx //MyDll = Dll ที่อยู่ใน Bin

<%
   string pageVariable1 = "Hello I love you";
   Response.Write(pageVariable1);
   MyDll.HelloWorld mydll = new MyDll.HelloWorld();
   Response.Write("<br>" + mydll.Say());
 %>


Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.033806 seconds to load.