代码之家  ›  专栏  ›  技术社区  ›  A191919

svcutil从dll获取wsdl和xsd

wcf
  •  0
  • A191919  · 技术社区  · 7 年前

    在命令提示符下启动

    svcutil "C:\Users\...\Documents\Visual Studio 2015\Projects\WcfServiceLibrary1\WcfServiceLibrary1\bin\Debug\WcfServiceLibrary1.dll"
    

    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Generating metadata files...
    C:\Windows\System32\tempuri.org.wsdl
    C:\Windows\System32\tempuri.org.xsd
    C:\Windows\System32\schemas.microsoft.com.2003.10.Serialization.xsd
    C:\Windows\System32\WcfServiceLibrary1.xsd
    

    但看起来里面没有任何文件的痕迹 C:\Windows\System32\

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace WcfServiceLibrary1
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            string GetData(int value);
    
            [OperationContract]
            CompositeType GetDataUsingDataContract(CompositeType composite);
    
            // TODO: Add your service operations here
        }
    
        // Use a data contract as illustrated in the sample below to add composite types to service operations.
        // You can add XSD files into the project. After building the project, you can directly use the data types defined there, with the namespace "WcfServiceLibrary1.ContractType".
        [DataContract]
        public class CompositeType
        {
            bool boolValue = true;
            string stringValue = "Hello ";
    
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
    
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }
    }
    

    实施:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace WcfServiceLibrary1
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
        public class Service1 : IService1
        {
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }
    
            public CompositeType GetDataUsingDataContract(CompositeType composite)
            {
                if (composite == null)
                {
                    throw new ArgumentNullException("composite");
                }
                if (composite.BoolValue)
                {
                    composite.StringValue += "Suffix";
                }
                return composite;
            }
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Abraham Qian    7 年前

    为了 svcutil公司 命令输入 ,文件在中创建 C:\Windows\SysWOW64系统 .

    分配输出文件夹。

    这是官方文件。

    https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-3.5/aa347733(v=vs.90)

    推荐文章