麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

Using Web Services for Remoting over the Internet.

2024-07-21 02:21:44
字體:
來源:轉載
供稿:網友
  • decoding and de-serializing of the request message
  • invoking the remote method
  • encoding and serialization of the response message

[webmethod]
public string syncprocessmessage(string request)
{
   // request: decoding and deserializing
   byte[] reqbytearray = convert.frombase64string(request);
   memorystream reqstream = new memorystream();
   reqstream.write(reqbytearray, 0, reqbytearray.length);
   reqstream.position = 0;
   binaryformatter bf = new binaryformatter();
   imessage reqmsg = (imessage)bf.deserialize(reqstream);
   reqmsg.properties["__uri"] = reqmsg.properties["__uri2"]; // work around!!
   reqstream.close();

   // action: invoke the remote method
   string[] stype = reqmsg.properties["__typename"].tostring().split(new char[]{','}); // split typename
   assembly asm = assembly.load(stype[1].trimstart(new char[]{' '})); // load type of the remote object
   type objecttype = asm.gettype(stype[0]);                           // type
   string objecturl = reqmsg.properties["__uri"].tostring();          // endpoint
   object ro = remotingservices.connect(objecttype, objecturl);       // create proxy
   traceimessage(reqmsg);
   imessage rspmsg = remotingservices.executemessage((marshalbyrefobject)ro,
                                                     (imethodcallmessage)reqmsg);
   traceimessage(rspmsg);

   // response: encoding and serializing
   memorystream rspstream = new memorystream();
   bf.serialize(rspstream, rspmsg);
   rspstream.position = 0;
   string response = convert.tobase64string(rspstream.toarray());
   rspstream.close();

   return response;
}

[webmethod]
public string syncprocesssoapmessage(string request)
{
   imessage retmsg = null;
   string response;

   try
   {
      trace.writeline(request);

      // request: deserialize string into the soapmessage
      soapformatter sf = new soapformatter();
      sf.topobject = new soapmessage();
      streamwriter rspsw = new streamwriter(new memorystream());
      rspsw.write(request);
      rspsw.flush();
      rspsw.basestream.position = 0;
      isoapmessage soapmsg = (isoapmessage)sf.deserialize(rspsw.basestream);
      rspsw.close();

      // action: invoke the remote method
      object[] values = soapmsg.paramvalues;
      string[] stype = values[2].tostring().split(new char[]{','});
      assembly asm = assembly.load(stype[1].trimstart(new char[]{' '}));
      type objecttype = asm.gettype(stype[0]);
      string objecturl = values[0].tostring();
      realproxywrapper rpw = new realproxywrapper(objecttype, objecturl,
                                                  soapmsg.paramvalues[4]);
      object ro = rpw.gettransparentproxy();
      methodinfo mi = objecttype.getmethod(values[1].tostring());
      object retval = mi.invoke(ro, values[3] as object[]);
      retmsg = rpw.returnmessage;
   }
   catch(exception ex)
   {
      retmsg = new returnmessage((ex.innerexception == null) ?
                                           ex : ex.innerexception, null);
   }
   finally
   {
      // response: serialize imessage into string
      stream rspstream = new memorystream();
      soapformatter sf = new soapformatter();
      remotingsurrogateselector rss = new remotingsurrogateselector();
      rss.setrootobject(retmsg);
      sf.surrogateselector = rss;
      sf.assemblyformat = formatterassemblystyle.full;
      sf.typeformat = formattertypestyle.typesalways;
      sf.topobject = new soapmessage();
      sf.serialize(rspstream, retmsg);
      rspstream.position = 0;
      streamreader sr = new streamreader(rspstream);
      response = sr.readtoend();
      rspstream.close();
      sr.close();
   }

   trace.writeline(response);
   return response;
}
the implementation of the steps are depended from the type of formatter such as soapformatter or binaryformatter. the first and last steps are straightforward using the remoting namespace classes. the second one (action) for the soapformatter message needed to create the following class to obtain imessage of the methodcall:
public class realproxywrapper : realproxy
{
   string _url;
   string _objecturi;
   imessagesink _messagesink;
   imessage _msgrsp;
   logicalcallcontext _lcc;

   public imessage returnmessage { get { return _msgrsp; }}
   public realproxywrapper(type type, string url, object lcc) : base(type)
   {
      _url = url;
      _lcc = lcc as logicalcallcontext;

      foreach(ichannel channel in channelservices.registeredchannels)
      {
         if(channel is ichannelsender)
         {
            ichannelsender channelsender = (ichannelsender)channel;
            _messagesink = channelsender.createmessagesink(_url, null, out _objecturi);
            if(_messagesink != null)
               break;
         }
      }

      if(_messagesink == null)
      {
         throw new exception("a supported channel could not be found for url:"+ _url);
      }
   }
   public override imessage invoke(imessage msg)
   {
      msg.properties["__uri"] = _url; // endpoint
      msg.properties["__callcontext"] = _lcc; // caller's callcontext
      _msgrsp = _messagesink.syncprocessmessage(msg);

      return _msgrsp;
   }
}// realproxywrapper
test
i built the following package to test functionality of the webservicelistener and webservicechannellib assemblies. note that this package has only test purpose. here is what you downloaded it:
  • consoleclient, the test console program to invoke the call over internet - client machine
  • consoleserver, the host process of the myremoteobject - server machine
  • myremoteobject, the remote object - server machine
  • webservicechannellib, the custom client channel
  • webservicelistener, the web service listener  - server machine

to recompile a package and its deploying in your environment follow these notes:
  • the folder webservicelistener has to be moved to the virtual directory (inetpub/wwwroot).
  • the myremoteobject assembly has to be install into the gac on  the server machine
  • the webservicechannellib assembly has to be install into the gac on the client machine
  • (option) the msmqchannellib assembly [1] has to be install into the gac on the server machine
  • the solution can be tested also using the same machine (win2k/adv server)
  • use the echo webmethod on the test page of the webservicelistener to be sure that this service will be work  

the test case is very simple. first step is to launch the consoleserver program. secondly open the consoleclient program and follow its prompt text. if everything is going right you will see a response from the remote object over internet. i am recommending to make a first test on the same machine and then deploying over internet.
conclusion
in this article has been shown one simple way how to implement a solution for remoting over internet. i used the power of .net technologies such as soap, remoting, reflection and web service. the advantage of this solution is a full transparency between the consumer and remote object. this logical connectivity can be mapped into the physical path using the config files, which they can be administratively changed.
 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久国产精品成人免费 | 97久色| 精品在线观看一区二区 | 欧美日韩高清一区二区三区 | 久久精品女人天堂av | 国产激情视频在线 | 欧美性猛交xxxxx按摩国内 | 毛片视频免费播放 | 九九热在线视频观看这里只有精品 | 久综合 | 黄色网址在线播放 | 欧美日韩在线中文字幕 | 黄色网址入口 | 久久久经典视频 | 国产精品v片在线观看不卡 成人一区二区三区在线 | 久久精品亚洲精品国产欧美kt∨ | 婷婷中文字幕一区二区三区 | 羞羞电影在线观看www | 女18一级大黄毛片免费女人 | 永久av在线免费观看 | 羞羞的网址 | 永久av在线免费观看 | 美女网站黄在线观看 | 久久国产在线观看 | 欧美a v在线 | 国人精品视频在线观看 | 日韩精品中文字幕在线播放 | 亚洲一级成人 | 国产午夜电影 | 国产精品美女久久久免费 | 久章草影院 | 久草在线视频新 | 自拍亚洲伦理 | 久久丝袜脚交足黄网站免费 | 49vv看片免费 | 久久久久久久久久亚洲精品 | 国产免费观看电影网站 | 国产二区三区在线播放 | 中文字幕在线观看免费视频 | 在线亚洲观看 | 一级在线视频 |