如何使用Visual Studio Code引用WSDL文件? [英] How to reference a WSDL file using Visual Studio Code?

查看:908
本文介绍了如何使用Visual Studio Code引用WSDL文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重要的免责声明.此问题与在VS Code中创建参考无关.

Important disclaimer. This question isn't about generating a proxy to WSDL. It's not about creating a reference in VS Code, neither.

我正在使用Visual Studio Code(最新更新,v1.8,11月16日),并且需要创建对使用WSDL和XSD文件描述的外部Web服务的调用.我想使用上述编辑器来做到这一点,并且最好不必编写所有代理并包围自己.

I'm using Visual Studio Code (latest update, v1.8 November 16) and I need to create a call to an external web service described using a WSDL and XSD file. I want to do that using the aforementioned editor and preferably not have to compose all the proxies and enveloping myself.

这可能吗?还是我不走运?

Is it possible or am I out of luck on this one?

如果在VS Code中不可行,最简单的选择是什么?我们是在谈论使用VS15生成类和调用并在文件上进行复制,还是我不熟悉的一种整洁的解决方法?

What would be the simplest alternative if it's not doable in VS Code? Are we talking about generating the classes and calls using VS15 and copying over the files or is there a neat workaround I'm not familiar with?

推荐答案

手动创建(从头开始)

如果从头开始构建并且不关心Visual Studio的工作方式,则可以从此处的此解决方案开始以一些基础知识开始,以及同一页面上接受的解决方案中引用的其他链接.

Manual Creation (from scratch)

If building from scratch and don't care about how Visual Studio does it, you can start with some basics from this solution here, as well as the other links referenced in the accepted solution on the same page.

作为参考,下面由Visual Studio add reference方法生成的某些文件存储在子文件夹 Web参考/ Example (其中 Example 是用于访问引用的变量的名称),并包含以下内容:

For reference, some of the files generated by the Visual Studio add reference method below, are stored within a subfolder Web References/Example (where Example is the name of the variable used to access the reference) and contains the following :

<?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文件(与上面的"filename"参数同名)

此文件是完整的原始wsdl源文件(格式正确的xml).

.wsdl file (same name as the 'filename' parameter from above)

This file is the complete raw wsdl source file (well formatted xml).

此文件包含用于初始化所有方法和属性的代码,并且是扩展System.Web.Services.Protocols.SoapHttpClientProtocol

This file contains code to initialize all the methods and properties and is the base class which extends System.Web.Services.Protocols.SoapHttpClientProtocol

分配给该类的属性(很抱歉,我正在从一个旧的VB.NET项目中剥离:如下所示:

The properties assigned to the class (sorry I am stripping from an old VB.NET project: look like the following :

<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个文件)

.datasource (1 file for each type)

示例代码

<?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项目中)


Use Visual Studio to build it for you, then open up again in VSCode

Inside Visual Studio, you can do the following (and copy the results out to your VSCode project)

在项目资源管理器"中右键单击您的项目,然后选择"添加>服务参考".

Right-click your project in Project explorer, and select Add > Service Reference..

在此屏幕上单击[高级]

在此屏幕上单击[添加Web参考]

输入指向WSDL位置的完整URL,然后按Enter.

Enter your full URL to the WSDL location and press Enter.

如果成功(找到格式正确的WSDL),将启用 [添加参考] 按钮.单击该按钮,它将引用添加到您的项目中.

If successful (well formatted WSDL is found), the [Add Reference] button will be enabled. Click that, and it will add the reference to your project.

这篇关于如何使用Visual Studio Code引用WSDL文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆