• C#之wsdl工具的使用


    webservice 调用与生成的过程,其实都非常简单,有人说,现在都说改用WCF了。要我说啊,WCF是微软典型的败笔而已,明明有webapi方便、简繁、快捷。

    俺在这里写写,只是为了记录一下,岁数大很容忘记东西,但凡高手直接绕过就好了。

    这个东西好像是大象装冰箱分,也就是1和2嘛

    1.生成客户端代码调用webservice代码

    wsdl E:\WS.wsdl /out:WS.cs

    这个生成代码和引用方式生成的代码几乎一样,代码这里就不卖弄了。这么干的理由也就是可以少一个引用动作而已。似乎有点先进性的感觉。

    2.反过来生成服务端

    wsdl /si C:\webserver.wsdl /out:D:\

    服务端代码当然是一个接口,大概如下


    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Serialization;

    //
    // 此源代码由 wsdl 自动生成, Version=4.0.30319.17929。
    //


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.17929")]
    [System.Web.Services.WebServiceBindingAttribute(Name="webserver", Namespace="http://localhost:8080/webserver.wsdl")]
    [System.Xml.Serialization.SoapIncludeAttribute(typeof(WebSoeInfo))]
    [System.Xml.Serialization.SoapIncludeAttribute(typeof(VarValue))]
    public interface IWebserver {

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:scada", ResponseNamespace="urn:scada")]
    [return: System.Xml.Serialization.SoapElementAttribute("result")]
    int UserLogin(string username, string password);

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:scada", ResponseNamespace="urn:scada")]
    [return: System.Xml.Serialization.SoapElementAttribute("result")]
    VarValue[] ReadVarValue(string varNameList);

    /// <remarks/>
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:scada", ResponseNamespace="urn:scada")]
    [return: System.Xml.Serialization.SoapElementAttribute("result")]
    int WriteVarValue(string varName, int waitTime, string value);


  • 相关阅读:
    让DBGrid不能插入记录
    利用Stream下载文件
    设置文本框只能输入数字
    正则表达式的使用
    在同一页面处理提交代码
    HTML集合属性的应用
    移动MAS短信API libmySQL.dll无法添加引用
    ArcServer for Silverlight系列之属性查询
    aspnet_wp.exe w3wp.exe
    更改嵌入互操作类型 无法从程序集**中嵌入互操作类型,因为该程序集缺少“ImportedFromTypeLibAttribute”特性或“PrimaryInteropAssemblyAttribute“特性
  • 原文地址:https://www.cnblogs.com/itjeff/p/16071217.html
Copyright © 2020-2023  润新知