wse2.0学习笔记--消息的接收

使用WSE2.0的soapclient和soapservice可以模拟WEBSERVICE的功能,区别是可以脱离IIS.这点很重要.

using System;
using System.Web;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Addressing;
using Microsoft.Web.Services2.Messaging;
using Microsoft.Web.Services2.Referral;
namespace MySoapReceiver
{
 /// <summary>
 /// This is a sample which allows the user to receive a message
 /// to a simple Web service.
 /// </summary>
 public class StockServiceHost
 {
       
  [MTAThread]
  static void Main(string[] args)
  {
   StockServiceHost host = null;
           
   //
   // Instantiate the host and run it        
   //
   try
   {
    host = new StockServiceHost();
    host.Run();
   }
   catch (Exception ex)
   {
    Console.WriteLine(ex.Message);              
   }            

   //
   // Wait for a final key press to close the application.
   //
   Console.WriteLine( "" );
   Console.WriteLine("Press any key to exit when done...");
   Console.WriteLine( "" );
   Console.ReadLine();
  }

  public void Run()
  {         
   //
   // Add the System.Type of the service (SoapServiceTest) to the SoapReceivers collection.
   // This will start a TCP-based listener if there isn't one already started.
   //
   Uri via = new Uri("soap.tcp://" + System.Net.Dns.GetHostName() +":8888");//外部地址
   Uri address = new Uri("soap://maxplatform.com/ServiceTest");//类地址
   EndpointReference endpoint = new EndpointReference(address, via);
           
   SoapReceivers.Add( endpoint, typeof(SoapServiceTest) );//添加到soapReceivers
   Console.WriteLine( "Listening for messages at:\n" + address );                    
  }           
 }
}
================receiver.cs

/*=====================================================================
  File:      Service.cs

  Summary:   This is a sample which represents a Web service

---------------------------------------------------------------------
 
=====================================================================*/

using System;
using System.Collections;

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


namespace MySoapReceiver
{
 
 [SoapActor("soap://maxplatform.com/ServiceTest")]//类地址
 public class SoapServiceTest : SoapService
 {
  
  [SoapMethod("SimpleServiceMethod")]//客户端需要有一个相同的代理方法.
  public string GetString( string message )
  {
   Console.WriteLine( "收到消息:\n " );
   Console.WriteLine(message);
   Console.WriteLine("返回消息:\n");
   string ret="\n服务器端收到了你发的消息:["+message+"]";
   Console.WriteLine(ret);
   return ret;
  }

  public static StockServiceHost host;
 }
}
 

转载于:https://www.cnblogs.com/meteorcui/archive/2004/12/22/2021260.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值