感激伤害你的人,因为他磨练了你的心志;感激欺骗你的人,因为他增进了你的智慧;感激中伤你的人,因为他砥砺了你的人格;感激鞭打你的人,因为他激发了你的斗志;感激遗弃你的人,因为他教导你该独立;感激绊倒你的人,因为他强化了你的双腿;感激斥责你的人,因为他提醒了你的缺点

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • ...
显示模式: 摘要 | 列表
程序重新启动自己
2009/06/15 17:41

System.Diagnostics.Process.Start(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe");
Application.Exit();

Tags: WinForm
使用WebRequest向页面发送数据
2009/06/08 12:33

Winform程序:
发送数据:
string path = AppDomain.CurrentDomain.BaseDirectory + "1.xml";
byte[] SomeBytes = new byte[1024];
WebRequest req = WebRequest.Create(http://localhost:6601/website/1.aspx);
req.Method = "POST";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(path);//要发送xml的路径.   
SomeBytes = Encoding.UTF8.GetBytes(xmldoc.OuterXml);
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
MessageBox.Show("发送完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

WebResponse wresp = req.GetResponse();      //接收返回数据
Stream respStream = wresp.GetResponseStream();
StreamReader reader = new StreamReader(respStream, Encoding.UTF8);
richTextBox1.Text = reader.ReadToEnd();
wresp.Close();

 

Web程序:
接收数据:
Stream s = HttpContext.Current.Request.InputStream;
byte[] buffer = new byte[1024];//无符号 8 位整数数组
int count = 0;
StringBuilder builder = new StringBuilder();//表示可变字符字符串。

while ((count = s.Read(buffer, 0, 1024)) > 0)//每次读取1024个字节
{
builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
}
string msgReturn = builder.ToString();

msgReturn 为接收到的字符串

 

//发送返回数据
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes("http://www.xt80");
HttpResponse hr = HttpContext.Current.Response;
hr.Clear();
hr.OutputStream.Write(bytes, 0, bytes.Length);
hr.OutputStream.Close();

Tags: ASP.NET,常用技术,WebForm
app_offline.htm的使用
2009/06/08 11:56

新建一个名为“app_offline.htm”的文件,放置在网站根目录下,可以使得网站自动定为至该文件显示,比如说要发布新版本的系统,可以实现放这么一个文件作为友情提示,部署完成之后删除即可,注:该文件必须大于512字节,2.0版本有效

Tags: ASP.NET,常用技术
WCF使用用户名和密码进行身份验证
2009/05/12 12:44

1、新建一个WCF Service Library项目,名字叫做WCFServiceLibrary1,代码就用默认的,以下是它的两个方法:
      public string MyOperation1(string myValue)
      public string MyOperation2(DataContract1 dataContractValue)

2、在WCFServiceLibrary1项目下新建一个类文件,名字叫做MyCustomValidator.cs,编写如下代码:
      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.IdentityModel.Selectors;
      using System.IdentityModel.Tokens;

      namespace WCFServiceLibrary1{
      public class MyCustomValidator:UserNamePasswordValidator{
          public override void Validate(string userName, string password)
          {
            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
                if (userName != "123456" || password != "123456")
                    throw new Exception("用户名和密码错误");
                else
                    throw new Exception("用户名和密码不能为空");
          }
       }    //为了节约地方,就这么堆起了

3、新建一个WCFService项目,名字是WCFService1,引用前面已经编译好的WCFServiceLibrary1.dll,打开Service.svc
      写入以下代码:

      <% @ServiceHost Language=C# Debug="true" Service="WCFServiceLibrary1.service1" CodeBehind="" %>
      
        使用Makecert 工具创建一个证书,命令如下:
        Makecert -r -pe -n "CN=MyServer" -ss My -sky exchange

4、Web.Config做如下配置,并运行WCFService项目:
      <system.serviceModel>
    <services>
      <service behaviorConfiguration="MyBehavior" name="WCFServiceLibrary1.service1">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="myBinding"
          contract="WCFServiceLibrary1.IService1" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehavior">
          <serviceCredentials>
            <serviceCertificate findValue="MyServer" storeName="My" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="WCFServiceLibrary1.MyCustomValidator,WCFServiceLibrary1" />
          </serviceCredentials>
          <serviceDebug httpsHelpPageEnabled="false" />
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="myBinding">
          <security>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>

6、使用svcutil.exe 工具生成客户端配置文件和代理类,使用方法:
       svcutil.exe http://localhost:4207/WCFService1/Service.svc?wsdl

7、新建一个Windows程序,叫做WindowsApplication1,首先添加如下引用:
      System.ServiceModel
      System.Runtime.Serialization

8、将前面生成的配置文件中的节点Copy到App.Config中,将代理类复制到WindowsApplication1下,在窗体上增加一个按钮,并写入下面的代码:
      private void button1_Click(object sender, EventArgs e)
        {
            Service1Client client = new Service1Client();
            client.ClientCredentials.UserName.UserName = "123456";
            client.ClientCredentials.UserName.Password = "123456";
            MessageBox.Show(client.MyOperation1("www.xt80.com"));
        }
       运行WindowsApplication1,将会看到返回信息:Hello:www.xt80.com

Tags: .NET Framework 3.0,WCF Service
把XML格式的字符串读进DataSet
2009/05/06 17:32

string poststr = "<?xml version='1.0' encoding='UTF-8'?>";
              poststr += "<MasMessage xmlns='http://www.xxx.com/interface'>";
              poststr += "  <version>1.0</version>";
              poststr += "  <TxnMsgContent>";
              poststr += "      <txnType>测试测试测试</txnType>";
              poststr += "      <cardNo>888888</cardNo>";
              poststr += "  </TxnMsgContent>";
              poststr += "</MasMessage>";
DataSet ds = new DataSet();
StringReader getsr = new StringReader(poststr );
ds.ReadXml(getsr);

Tags: XML,ASP.NET
用Post方式调用WebService
2009/03/03 17:50

以下代码是在WinForm中完成的:
第一步:先将需要Post的XML写成一个文件,这里写成test.xml,调用的时候将其中的参数修改以下就可以了,以下是一个样本:
<?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>
    <GetOrderformInfo xmlns="http://samples.com/">
      <orderid>00001</orderid>
      <leaguerid>0</leaguerid>
      <prjtype>4</prjtype>
    </GetOrderformInfo>
  </soap:Body>
</soap:Envelope>

第二步:CS代码:
/// <summary>
        /// 调用WebService的方法
        /// </summary>
        /// <param name="filename">POST所用文件</param>
        /// <param name="requestURL">调用地址</param>
        /// <param name="SOAPActionURL"></param>
        /// <returns></returns>
        private string Post(string filename,string requestURL,string SOAPActionURL)
        {
            XmlDataDocument doc = new XmlDataDocument();
            doc.Load(filename);
            byte[] data = System.Text.Encoding.UTF8.GetBytes(doc.OuterXml);
            WebRequest request = WebRequest.Create(requestURL);
            request.Method = "POST";
            request.Headers.Add("SOAPAction", SOAPActionURL);
            request.Headers.Add("ContentLength", data.Length.ToString());
            request.ContentType = "text/xml; charset=utf-8";

            Stream OWrite = request.GetRequestStream();
            OWrite.Write(data, 0, data.Length);
            OWrite.Close();

            Stream oRead = null;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            oRead = response.GetResponseStream();
            XmlDataDocument resultdoc = new XmlDataDocument();
            resultdoc.Load(oRead);
            return resultdoc.InnerText.ToString();
        }

private void button5_Click(object sender, EventArgs e)
        {
            string filename = AppDomain.CurrentDomain.BaseDirectory + "xmlfiles/UpdatePaymentInfo.xml";
            string requestURL = "http://localhost/samples/test.asmx?op=MyTest";
            string SOAPActionURL = "http://samples.com/MyTest";
            /*这里可以增加修改XML文件参数的代码....*/
            richTextBox1.Text = Post(filename, requestURL, SOAPActionURL).Trim();   //这里调用后显示结果
        }

注:XML样本和SOAPAction地址在WebService的请求和响应示例里面有说明

Tags: WebService,ASP.NET
IIS启动不了.提示服务没有及时响应启动或控制请求解决办法
2009/02/20 15:42

1:在“服务(本地)”里有一项Eventlog和HTTP SSL都和IIS的或World Wide Web Publishing Services所以来的服务项 打开它们
2:在“服务(本地)”里中的World Wide Web Publishing Services所需要依赖的服务(Dependencies),看到是IIS Admin Service。进而发现IIS Admin Service也无法启动,再查IIS Admin Service的Dependencies,查的结果是Protected Storage和RPC(Remote Procedure Call),于是启动RPC,接着顺利启动IIS Admin Service,接着启动World Wide Web Publishing Services,于是IIS恢复正常。

注:若启动World Wide Web Publishing Services服务出现127错误(找不到指定的程序),原因是在微软补丁KB939373,卸载掉就可以了

Tags: IIS
在update语句中使用联合查询
2009/02/18 16:43


update A set A.TeamCustomerID = B.TeamCustomerID  from D_Team_Sign_Contact A
left outer join D_Team_Customer B
on A.SignContactID = B.SignContactID
where A.teamID = 'ETCGN20090214YY'
and IsContect = 1

Tags: SQL语句,SQL SERVER 2005
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • ...
显示模式: 摘要 | 列表
GOOG搜索
日历
分类
全部文章[205]
.NET技术[143]
VB技术[2]
AJAX技术[3]
数据库技术[14]
XML技术[1]
HTML网页[9]
ASP技术[12]
JavaScript[10]
WebService[3]
其他技术[5]
技术规范[2]
Oracle技术[1]
统计
最新更新
程序重新启动自己使用WebRequest向页面发送数据app_offline.htm的使用WCF使用用户名和密码进行身份验证把XML格式的字符串读进DataSet用Post方式调用WebServiceIIS启动不了.提示服务没有及时响应启动或控制在update语句中使用联合查询将对象序列化成XML字符串在JS中接收URL参数
最新评论
热门文章
最新留言
站长信息
昵称:admin
[给我发短消息]
QQ:
Email:root@xt80.com
MSN:
归档
2009/04[0]2009/05[2]2009/06[3]2009/07[0]