手动创建(从头开始)
如果从头开始构建并且不关心 Visual Studio 是如何做到的,您可以从一些基础知识 from this solution here 以及同一页面上已接受的解决方案中引用的其他链接开始。
使用与 Visual Studio 相同的方法手动创建
作为参考,下面的 Visual Studio 添加引用方法生成的一些文件存储在子文件夹 Web References/Example 中(其中 Example 是用于访问引用的变量的名称)并包含以下内容:
.map 文件
<?xml version="1.0" encoding="utf-8"?>
<DiscoveryClientResultsFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Results>
<DiscoveryClientResult referenceType="System.Web.Services.Discovery.ContractReference" url="http://example.com/api/index.php?wsdl" filename="index.wsdl" />
</Results>
</DiscoveryClientResultsFile>
.wsdl 文件(与上面的“文件名”参数同名)
此文件是完整的原始 wsdl 源文件(格式良好的 xml)。
参考文件
该文件包含初始化所有方法和属性的代码,是扩展System.Web.Services.Protocols.SoapHttpClientProtocol的基类
分配给类的属性(对不起,我从旧的 VB.NET 项目中剥离:如下所示:
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.6.1586.0"), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Web.Services.WebServiceBindingAttribute(Name:="ExampleAPIBinding", [Namespace]:="urn:ExampleAPI"), _
System.Xml.Serialization.SoapIncludeAttribute(GetType(MyCustomType1)), _
System.Xml.Serialization.SoapIncludeAttribute(GetType(MyCustomType2)), _
Partial Public Class ExampleAPI
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
End Class
.datasource(每种类型1个文件)
示例代码
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="MyMethodName" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>ExampleAPI.SOAP.ClientMerchant, Web References.SOAP.Reference.vb.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
使用 Visual Studio 为您构建它,然后在 VSCode 中再次打开
在 Visual Studio 中,您可以执行以下操作(并将结果复制到您的 VSCode 项目中)
步骤 1
在项目资源管理器中右键单击您的项目,然后选择添加 > 服务引用..
第二步
点击此屏幕上的[高级]
第三步
单击此屏幕上的 [添加 Web 引用]
第四步
输入 WSDL 位置的完整 URL,然后按 Enter。
终于
如果成功(找到格式良好的 WSDL),[添加引用] 按钮将被启用。单击它,它将添加对您项目的引用。