Richie

Sometimes at night when I look up at the stars, and see the whole sky just laid out there, don't you think I ain't remembering it all. I still got dreams like anybody else, and ever so often, I am thinking about how things might of been. And then, all of a sudden, I'm forty, fifty, sixty years old, you know?

WSE 3.0异步调用, MTOM, Custom Policy Trace Assertion

    1. 异步调用Web Service
    对Web Service端没有要求,只是Client端调用方法上不同。
private string _guid = Guid.NewGuid().ToString().ToUpper();

MyServiceRef.MyServiceWse serviceProxy 
= new WSEClient.MyServiceRef.MyServiceWse();
serviceProxy.HelloWorldCompleted 
+=
        new
 WSEClient.MyServiceRef.HelloWorldCompletedEventHandler(serviceProxy_HelloWorldCompleted);
serviceProxy.HelloWorldAsync(_guid);

private void serviceProxy_HelloWorldCompleted(object sender, MyServiceRef.HelloWorldCompletedEventArgs args)
{
    
if (args.Error != null)
    {
        
//process for exception
    }
    
else if (args.Cancelled)
    {
        
//cancelled
    }
    
else
    {
        
//process for success
        string result = args.Result;
    }
}
    取消调用:serviceProxy.CancelAsync(_guid);,客户端的处理被立刻Cancel,服务器端则不一定,可能需要等到Web Service方法执行完毕。

    2. Custom Policy Trace Assertion
    参考WSE 3.0 samples中的CustomPolicyTraceAssertion。首先分别继承PolicyAssersion和SoapFilter两个类,实现自定义的Trace功能,然后参照Samples的wse3policyCache.config手工添加相关的配置节点。
    另外需要注意的一点是WSE 3.0 Server端和Client端output filter、input filter的处理机制,弄明白每一个SOAP消息在经过output filter或者input filter前后所发生的变化,以及对应于security policy配置文件中的位置关系,这样能准确地确定你需要记录的Trace的信息。以CustomPolicyTraceAssertion的Sample为例,假如Web Service端的配置如下:
   
    图中的input1.xml、input2.xml、output1.xml、output2.xml所截取的SOAP消息位置分别如下图:
   
    下标为2的文件截取的都是经过WSE签名、加密处理之后的SOAP消息,而下标为1的则是未经过WSE签名、加密的原始SOAP消息。上图只是一个示例,在WSE 3.0的Sample中,两个traceAssertion中的inputfile必须为同一个文件,outputfile也一样。你可以选择只记录未加密的SOAP消息,只需要删除第一个traceAssertion就可以。

    3. MTOM
    MTOM在WSE 3.0中用于服务器端和客户端传递二进制文件等数据,或者用于大数据量的消息。MTOM允许在传递大数据量或二进制文件时使用WSE 3.0消息层的安全性机制,另外对于大数据量采用了优化措施,提高传输效率。
    使用MTOM很简单,首先使用WSE 3.0 Settings工具分别为Web Service和Client设置启用MTOM(或者也可以在代码上进行设置),然后传送方将要传送的数据转化成byte[]发送给接收方,接受方收到数据后保存成文件或做其他处理。WSE 3.0 Samples中的MTOM示例演示了三种方式:不加密传输、加密传输、通过IXmlSerializable直接使用网络流(Network Stream)传输。

    把WSE 3.0的代码翻看了一下,本来准备对filter、pipeline方面调用序列、大致处理,以及数字签名处理过程、CA证书的使用细节等方面再详细写一写,但这篇post已经挂在草稿中2个多月了,一直没有时间来整理。

posted on 2007-06-09 06:22  riccc  阅读(813)  评论(0编辑  收藏  举报

导航