以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Dot NET,C#,ASP,VB 』  (http://bbs.xml.org.cn/list.asp?boardid=43)
----  [求助]看用wsdl.exe把wsdl文件生成客户端代理类的一个例子所遇到的很多疑问  (http://bbs.xml.org.cn/dispbbs.asp?boardid=43&rootid=&id=11425)


--  作者:myname2
--  发布时间:10/30/2004 12:07:00 PM

--  [求助]看用wsdl.exe把wsdl文件生成客户端代理类的一个例子所遇到的很多疑问

学习创建XML Web services时看到这个例子,这个服务是分析matchserver.html页的内容并返回数据.
他先是建立了一个服务说明文档.wsdl文件,然后用wsdl.exe生成了代理类,然后有个窗体页.aspx,可以通过点击该页上的一个button就可以看到返回的数据.

我看了用wsdl.exe自动生成的.vb文件,如下:

**********************
Option Strict Off
Option Explicit On

Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

'
'此源代码由 wsdl, Version=1.1.4322.573 自动生成。
'

'<remarks/>
<System.Diagnostics.DebuggerStepThroughAttribute(),  _
System.ComponentModel.DesignerCategoryAttribute("code")>  _
Public Class TestIt
    Inherits System.Web.Services.Protocols.HttpGetClientProtocol
    
    '<remarks/>
    Public Sub New()
        MyBase.New
        Me.Url = "http://localhost"
    End Sub
    
    '<remarks/>
    <System.Web.Services.Protocols.HttpMethodAttribute(GetType(System.Web.Services.Protocols.TextReturnReader), GetType(System.Web.Services.Protocols.UrlParameterWriter))>  _
    Public Function TestHeaders() As TestHeadersMatches
        Return CType(Me.Invoke("TestHeaders", (Me.Url + "/QuickStart1/MatchServer.html"), New Object(-1) {}),TestHeadersMatches)
    End Function
    
    '<remarks/>
    Public Function BeginTestHeaders(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
        Return Me.BeginInvoke("TestHeaders", (Me.Url + "/QuickStart1/MatchServer.html"), New Object(-1) {}, callback, asyncState)
    End Function
    
    '<remarks/>
    Public Function EndTestHeaders(ByVal asyncResult As System.IAsyncResult) As TestHeadersMatches
        Return CType(Me.EndInvoke(asyncResult),TestHeadersMatches)
    End Function
End Class

Public Class TestHeadersMatches
    
    <System.Web.Services.Protocols.MatchAttribute("TITLE>(.*?)<")>  _
    Public Title As String
    
    <System.Web.Services.Protocols.MatchAttribute("H1>(.*?)<")>  _
    Public H1 As String
End Class
**********************
我对其中的testheadersmatches这个类怎么来的不是很理解.
象类 TestIt 我知道是在.wsdl文件里的service name="TestIt"有定义,而TestHeaders方法在.wsdl文件里的operation name="TestHeaders" 有定义.那testheadersmatches是在wsdl文件里的什么地方定义的呢?

.wsdl文件如下:
************************
<?xml version="1.0"?>
<definitions xmlns:s="http://www.w3.org/1999/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:s0="http://tempuri.org/">
  <message name="TestHeadersHttpGetIn"/>
  <message name="TestHeadersHttpGetOut">
    <part name="Body" type="s:string"/>
  </message>
  <portType name="TestItHttpGet">          
    <operation name="TestHeaders">
      <input message="s0:TestHeadersHttpGetIn"/>
      <output message="s0:TestHeadersHttpGetOut"/>
    </operation>
  </portType>
  <binding name="TestItHttpGet" type="s0:TestItHttpGet">
    <http:binding verb="GET"/>
    <operation name="TestHeaders">
      <http:operation location="/QuickStart1/MatchServer.html"/>
      <input>
        <http:urlEncoded/>
      </input>
      <output>
         <text xmlns="http://microsoft.com/wsdl/mime/textMatching/">
          <match name='Title' pattern='TITLE&gt;(.*?)&lt;'/>
          <match name='H1' pattern='H1&gt;(.*?)&lt;'/>
  </text>
      </output>
    </operation>
  </binding>
  <service name="TestIt">
    <port name="TestItHttpGet" binding="s0:TestItHttpGet">
      <http:address location="http://localhost" />
    </port>
  </service>
</definitions>
**************************
其实我还是对wsdl文件里<binding>部分的一些元素不太理解.比如说上面这个文件定义了两个消息,其中的TestHeadersHttpGetIn没有part部分,把它作为请求消息发送给服务时,服务到底收到了什么内容;而TestHeadersHttpGetOut有part部分,类型为string,把它作为响应消息,那它从服务返回时带回的内容是什么?我又是通过什么方法接收的呢?

另外在<input>块里的<http:urlEncoded/>它到底把什么进行编码了?
而<output>块里的
<text xmlns="http://microsoft.com/wsdl/mime/textMatching/">
<match name='Title' pattern='TITLE&gt;(.*?)&lt;'/>
<match name='H1' pattern='H1&gt;(.*?)&lt;'/>
</text>
text、match这些元素又其什么作用呢,他们是什么类型的呢?

还有命名空间是不是都有一个架构文件呢?象上面这个xmlns="http://microsoft.com/wsdl/mime/textMatching/",怎么看不到呢?


aspx文件如下:
********************
<html>

<script language="VB" runat="server">

    Sub GetQuote(Src As Object, E As EventArgs)
        Try
            Dim matcher As New TestIt()
            Dim matches As TestHeadersMatches
            matches = matcher.TestHeaders()
            Title.InnerHtml = matches.Title
            H1.InnerHtml = matches.H1
   
            StockDetails.Visible = true
        Catch Exc As Exception
            Message.InnerHtml = "A network error occured or the service was unable to locate the symbol, please try again."
        End Try
    End Sub

</script>

<body bgcolor="ffffee" style="font: 10pt verdana">

  <h4>Using Html Text Pattern Matching Sample</h4>

  <form runat="server">
    <table style="font: 10pt verdana" width="300">
      <tr>
        <td></td>
        <td><input type="submit" OnServerClick="GetQuote" runat="server"/></td>
      </tr>
    </table>
    <p>
    <hr>
    <p>
    <table id="StockDetails" visible="false" runat="server" style="font: 8pt verdana" border=1>
      <tr>
        <td><b>Company Name</b></td>
        <td><span id="Title" runat="server"/></td>
      </tr>
      <tr>
        <td><b>H1 Text</b></td>
        <td><span id="H1" runat="server"/></td>
      </tr>
       
    </table>
    <p>
    <span id="Message" EnableViewState="false" runat="server"/>
    <p>
  </form>

</body>
</html>
********************************

matchservice.html文件如下:
********************************
<HTML>
<HEAD>
<TITLE>Hello!</TITLE>
</HEAD>

<BODY>
<H1>Hi Again!</H1>
</BODY>
</HTML>
*********************************


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
37.109ms