zoukankan      html  css  js  c++  java
  • .NET WEB SERVICE 学习记录

    建立WEB SERVICE的server端
        用VS2003, “文件”-》“新建” -》“项目” -》“C#项目”-》“ASP.NET WEB 服务”
    新建项目名称为MYWEBSERVICE1,代码如下,不要忘了引用“System.Data.OracleClient”

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    using System.IO;
    using System.Data.OracleClient;

    namespace mywebservice
    {
        [WebService(Namespace
    ="http://localhost/mywebservice/")]
        
    /// <summary>
        
    /// Service1 的摘要说明。
        
    /// </summary>

        public class Service1 : System.Web.Services.WebService
        
    {
            
    public Service1()
            
    {
                
    //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
                InitializeComponent();
            }


            
    组件设计器生成的代码

            
    // WEB 服务示例
            
    // HelloWorld() 示例服务返回字符串 Hello World
            
    // 若要生成,请取消注释下列行,然后保存并生成项目
            
    // 若要测试此 Web 服务,请按 F5 键
            [Serializable] 
                
    public class Person 
            

                
    public Person() 
                

                }
     

                
    public Person(string name,string gender) 
                

                    
    this.Name=name; 
                    
    this.Gender=gender; 
                }
     

                
    public string Name=""
                
    public string Gender=""
            }
     
            [WebMethod(CacheDuration
    =60)] 
            
    public Person[] GetPersons() 
            

                Person Alice
    =new Person("Alice","Female"); 
                Person Bob
    =new Person("Bob","Male"); 
                Person Chris
    =new Person("Chris","Female"); 
                Person Dennis
    =new Person("Dennis","Male"); 

                
    return new Person[]{Alice,Bob,Chris,Dennis}
            }
     


            [WebMethod] 
            
    public string GetPersonTable() 
            

                OracleConnection Ocon 
    = 


    编译后出来的WEB SERVICE的服务是http://localhost/mywebservice

                       WSDL文件位置为:http://localhost/mywebservice/Service1.asmx?WSDL
    内容如下:

      <?xml version="1.0" encoding="utf-8" ?> 
    <wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/mywebservice/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://localhost/mywebservice/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://localhost/mywebservice/">
    <s:element name="GetPersons">
      
    <s:complexType /> 
      
    </s:element>
    <s:element name="GetPersonsResponse">
    <s:complexType>
    <s:sequence>
      
    <s:element minOccurs="0" maxOccurs="1" name="GetPersonsResult" type="tns:ArrayOfPerson" /> 
      
    </s:sequence>
      
    </s:complexType>
      
    </s:element>
    <s:complexType name="ArrayOfPerson">
    <s:sequence>
      
    <s:element minOccurs="0" maxOccurs="unbounded" name="Person" nillable="true" type="tns:Person" /> 
      
    </s:sequence>
      
    </s:complexType>
    <s:complexType name="Person">
    <s:sequence>
      
    <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" /> 
      
    <s:element minOccurs="0" maxOccurs="1" name="Gender" type="s:string" /> 
      
    </s:sequence>
      
    </s:complexType>
    <s:element name="GetPersonTable">
      
    <s:complexType /> 
      
    </s:element>
    <s:element name="GetPersonTableResponse">
    <s:complexType>
    <s:sequence>
      
    <s:element minOccurs="0" maxOccurs="1" name="GetPersonTableResult" type="s:string" /> 
      
    </s:sequence>
      
    </s:complexType>
      
    </s:element>
      
    </s:schema>
      
    </wsdl:types>
    <wsdl:message name="GetPersonsSoapIn">
      
    <wsdl:part name="parameters" element="tns:GetPersons" /> 
      
    </wsdl:message>
    <wsdl:message name="GetPersonsSoapOut">
      
    <wsdl:part name="parameters" element="tns:GetPersonsResponse" /> 
      
    </wsdl:message>
    <wsdl:message name="GetPersonTableSoapIn">
      
    <wsdl:part name="parameters" element="tns:GetPersonTable" /> 
      
    </wsdl:message>
    <wsdl:message name="GetPersonTableSoapOut">
      
    <wsdl:part name="parameters" element="tns:GetPersonTableResponse" /> 
      
    </wsdl:message>
    <wsdl:portType name="Service1Soap">
    <wsdl:operation name="GetPersons">
      
    <wsdl:input message="tns:GetPersonsSoapIn" /> 
      
    <wsdl:output message="tns:GetPersonsSoapOut" /> 
      
    </wsdl:operation>
    <wsdl:operation name="GetPersonTable">
      
    <wsdl:input message="tns:GetPersonTableSoapIn" /> 
      
    <wsdl:output message="tns:GetPersonTableSoapOut" /> 
      
    </wsdl:operation>
      
    </wsdl:portType>
    <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
      
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
    <wsdl:operation name="GetPersons">
      
    <soap:operation soapAction="http://localhost/mywebservice/GetPersons" style="document" /> 
    <wsdl:input>
      
    <soap:body use="literal" /> 
      
    </wsdl:input>
    <wsdl:output>
      
    <soap:body use="literal" /> 
      
    </wsdl:output>
      
    </wsdl:operation>
    <wsdl:operation name="GetPersonTable">
      
    <soap:operation soapAction="http://localhost/mywebservice/GetPersonTable" style="document" /> 
    <wsdl:input>
      
    <soap:body use="literal" /> 
      
    </wsdl:input>
    <wsdl:output>
      
    <soap:body use="literal" /> 
      
    </wsdl:output>
      
    </wsdl:operation>
      
    </wsdl:binding>
    <wsdl:service name="Service1">
      
    <documentation xmlns="http://schemas.xmlsoap.org/wsdl/" /> 
    <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
      
    <soap:address location="http://localhost/mywebservice/Service1.asmx" /> 
      
    </wsdl:port>
      
    </wsdl:service>
      
    </wsdl:definitions>
  • 相关阅读:
    1024X768大图 (Wallpaper)
    (Mike Lynch)Application of linear weight neural networks to recognition of hand print characters
    瞬间模糊搜索1000万基本句型的语言算法
    单核与双核的竞争 INTEL P4 670对抗820
    FlashFTP工具的自动缓存服务器目录的功能
    LDAP over SSL (LDAPS) Certificate
    Restart the domain controller in Directory Services Restore Mode Remotely
    How do I install Active Directory on my Windows Server 2003 server?
    指针与指针变量(转)
    How to enable LDAP over SSL with a thirdparty certification authority
  • 原文地址:https://www.cnblogs.com/enli/p/133940.html
Copyright © 2011-2022 走看看