找回密码
 立即注册
搜索
查看: 689|回复: 5

请教关于web service的问题

[复制链接]

34

主题

757

回帖

1051

积分

金牌会员

first

积分
1051
发表于 2007-10-17 12:25:36 | 显示全部楼层 |阅读模式
想把web service收到的soap message存到一个文件里。有什么方法可以实现?
三 四 五 六 七
十 十 十 十 十
而 不 知 花 古
立 惑 天 甲 稀
    命    

72

主题

1118

回帖

1645

积分

金牌会员

积分
1645
发表于 2007-10-17 15:27:17 | 显示全部楼层
用什么语言开发? 如果是C#就很简单
回复

使用道具 举报

34

主题

757

回帖

1051

积分

金牌会员

first

积分
1051
 楼主| 发表于 2007-10-17 21:09:27 | 显示全部楼层
我是想用vb,但是C#也行。C# 怎么做?
三 四 五 六 七
十 十 十 十 十
而 不 知 花 古
立 惑 天 甲 稀
    命    
回复

使用道具 举报

403

主题

3329

回帖

5022

积分

网站编辑

积分
5022
发表于 2007-10-18 14:40:39 | 显示全部楼层
你的Web Service的接口函数打算写成什么样?
回复

使用道具 举报

34

主题

757

回帖

1051

积分

金牌会员

first

积分
1051
 楼主| 发表于 2007-10-18 22:15:31 | 显示全部楼层
想用soap extension。接口函数什么也不做,call这个函数的时候,soap extension就把进来的soap message全部存到一个文件里。不知道有没有什么更好的办法。
三 四 五 六 七
十 十 十 十 十
而 不 知 花 古
立 惑 天 甲 稀
    命    
回复

使用道具 举报

34

主题

757

回帖

1051

积分

金牌会员

first

积分
1051
 楼主| 发表于 2007-10-18 22:19:49 | 显示全部楼层
<%@ WebService Language="vb"  Class="ReceiveWS" %>

Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
Imports System.IO
   
Namespace ReceiveWS

    <WebService()> _
    Public Class ReceiveWS

        Inherits WebService
               
        Private Const strAction As String = "OP_ReceiveEventInformation"
        Private strFilename As String = "D:\Website\" & DateTime.Now.ToString("MM-dd-yy_HHmm") & ".xml"
        
        <TraceExtension(), _
        WebMethod(Description:="Accepts MSG_FullEventUpdate message as SOAP request"), _
        SoapDocumentMethod(Action:=strAction, _
                                   ParameterStyle:=SoapParameterStyle.Bare)> _
        Public Function OP_ReceiveEventInformation() As String
        
            Try
                Return strFilename
        
            Catch err As Exception
                ' Create the detail information
                ' an <ExceptionType> element with the type name.
                Dim doc As XmlDocument = New XmlDocument()
                Dim node As XmlNode = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace)
                Dim child As XmlNode = doc.CreateNode(XmlNodeType.Element, "ExceptionType", SoapException.DetailElementName.Namespace)
                child.InnerText = err.GetType().ToString()
                node.AppendChild(child)

                ' Create the custom SoapException.
                ' Use the message from the original exception,
                ' and add the detail information.
                Dim soapErr As SoapException = New SoapException(err.Message, SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri, node)

                ' Throw the revised SoapException.
                Throw soapErr
            End Try
                  
        End Function
        
    End Class
   
    ' Define a SOAP Extension that traces the SOAP request and SOAP response
    ' for the XML Web service method the SOAP extension is applied to.
    <WebService()> _
    Public Class TraceExtension
        
        Inherits SoapExtension

        Private Const strOutputPath As String = "D:\Website\"
        Private oldStream As Stream
        Private newStream As Stream
        Private m_filename As String

        ' Save the Stream representing the SOAP request or SOAP response into
        ' a local memory buffer.
        Public Overrides Function ChainStream(ByVal stream As Stream) As Stream
            oldStream = stream
            newStream = New MemoryStream()
            Return newStream
        End Function

        ' When the SOAP extension is accessed for the first time, the XML Web
        ' service method it is applied to is accessed to store the file
        ' name passed in, using the corresponding SoapExtensionAttribute.   
        Public Overloads Overrides Function GetInitializer(ByVal methodInfo As _
            LogicalMethodInfo, _
        ByVal attribute As SoapExtensionAttribute) As Object
            Return CType(attribute, TraceExtensionAttribute).Filename
        End Function

        ' The SOAP extension was configured to run using a configuration file
        ' instead of an attribute applied to a specific XML Web service
        ' method.  Return a file name based on the class implementing the Web
        ' Service's type.
        Public Overloads Overrides Function GetInitializer(ByVal WebServiceType As _
          Type) As Object
            ' Return a file name to log the trace information to, based on the
            ' type.
            Return strOutputPath & DateTime.Now.ToString("MM-dd-yy_HHmm") & ".xml"
        End Function

        ' Receive the file name stored by GetInitializer and store it in a
        ' member variable for this specific instance.
        Public Overrides Sub Initialize(ByVal initializer As Object)
            m_filename = CStr(initializer)
        End Sub

        ' If the SoapMessageStage is such that the SoapRequest or SoapResponse
        ' is still in the SOAP format to be sent or received over the network,
        ' save it out to file.
        Public Overrides Sub ProcessMessage(ByVal message As SoapMessage)
            Select Case message.Stage
                Case SoapMessageStage.BeforeSerialize
                Case SoapMessageStage.AfterSerialize
                    'WriteOutput(message)
                Case SoapMessageStage.BeforeDeserialize
                    WriteInput(message)
                Case SoapMessageStage.AfterDeserialize
                Case Else
                    Throw New Exception("invalid stage")
            End Select
        End Sub

        '' Write the SOAP message out to a file.
        'Public Sub WriteOutput(ByVal message As SoapMessage)
        '    newStream.Position = 0
        '    Dim fs As New FileStream(m_filename, FileMode.Append, _
        '                             FileAccess.Write)
        '    Dim w As New StreamWriter(fs)
        '    w.WriteLine("-----Response at " + DateTime.Now.ToString("MM-dd-yy_HHmm"))
        '    w.Flush()
        '    Copy(newStream, fs)
        '    w.Close()
        '    newStream.Position = 0
        '    Copy(newStream, oldStream)
        'End Sub

        ' Write the SOAP message out to a file.
        Public Sub WriteInput(ByVal message As SoapMessage)
            Copy(oldStream, newStream)
            Dim fs As New FileStream(m_filename, FileMode.Create, _
                                     FileAccess.Write)
            Dim w As New StreamWriter(fs)

            'w.WriteLine("----- Request at " + DateTime.Now.ToString("MM-dd-yy_HH:mm:ss"))
            w.Flush()
            newStream.Position = 0
            Copy(newStream, fs)
            w.Close()
            newStream.Position = 0
        End Sub

        Sub Copy(ByVal fromStream As Stream, ByVal toStream As Stream)
            Dim reader As New StreamReader(fromStream)
            Dim writer As New StreamWriter(toStream)
            writer.WriteLine(reader.ReadToEnd())
            writer.Flush()
        End Sub
    End Class

    ' Create a SoapExtensionAttribute for our SOAP Extension that can be
    ' applied to an XML Web service method.
    <AttributeUsage(AttributeTargets.All)> _
    Public Class TraceExtensionAttribute
        
        Inherits SoapExtensionAttribute

        Private m_filename As String = "D:\Website\" & DateTime.Now.ToString("MM-dd-yy_HHmm") & ".xml"
        Private m_priority As Integer = 1

        Public Overrides ReadOnly Property ExtensionType() As Type
            Get
                Return GetType(TraceExtension)
            End Get
        End Property

        Public Overrides Property Priority() As Integer
            Get
                Return m_priority
            End Get
            Set(ByVal Value As Integer)
                m_priority = Value
            End Set
        End Property

        Public Property Filename() As String
            Get
                Return m_filename
            End Get
            Set(ByVal Value As String)
                m_filename = Value
            End Set
        End Property
        
    End Class

End Namespace
三 四 五 六 七
十 十 十 十 十
而 不 知 花 古
立 惑 天 甲 稀
    命    
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|海浩社区

GMT+8, 2025-9-15 07:26 , Processed in 0.087394 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表