WSE2.0学习--消息的发送

client端:

Main.cs =====================================================================*/

using System;

using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Addressing;
using Microsoft.Web.Services2.Messaging;
namespace MySoapClient
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class MySoapClient
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   MySoapClient client = null;

   //
   // Instantiate the client and run it
   //
   try
   {
    client = new MySoapClient();
    client.Run();
   }
   catch (Exception ex)
   {
    Console.WriteLine(ex.Message);
   }

   //
   // Wait for a final key press to close the application.
   //
   Console.WriteLine( "" );
   Console.WriteLine("Press [Enter] to continue...");
   Console.WriteLine( "" );
   Console.ReadLine();
  }
  public void Run()
  {
   //
   // Create a request message that includes two stock symbols (FABRIKAM and CONTOSO).
   // Next, create a StockQuoteClient for the destination of the TCP-hosted service.
   // Finally, call the service.
   //
   

   Uri address = new Uri("soap://maxplatform.com/ServiceTest");//要调用的类
   Uri via = new Uri("soap.tcp://" + System.Net.Dns.GetHostName() + ":8888");//tcp:主机地址:端口号
           
   ClientTest proxy      = new ClientTest( new EndpointReference(address, via));//代理类==服务器端类
   Console.WriteLine("Calling {0}",proxy.Destination.Address.Value);
   string  retString     = proxy.GetString( "这是Client端要发送的数据." );//代理类的方法==服务器端类的方法
           
   //
   // The response was successfully received.
   // Display the results.
   //
   Console.WriteLine("与service建立连接成功,收到返回的消息:");
   Console.WriteLine(retString);
   
  }
 }
}

 

=========Client.cs

/*=====================================================================
  File:     Client.cs
 
  Summary:   This is a sample which represents a client to a Web service
 
---------------------------------------------------------------------
 
=====================================================================*/

using System;

using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Addressing;
using Microsoft.Web.Services2.Messaging;

 

namespace MySoapClient
{
    //client端,继承自soapclient
    public class ClientTest : SoapClient
    {
        public ClientTest( EndpointReference endpoint ) : base( endpoint ){}

      
        [SoapMethod("SimpleServiceMethod")]//代理soapmethod=服务器端的method
        public string GetString( string message )
        {

            return (string)base.SendRequestResponse("GetString",message ).GetBodyObject(typeof(string));
        }
    }
}
 

posted @ 2004-12-22 02:19  meteorcui  阅读(175)  评论(0编辑  收藏  举报