簡體   English   中英

如何僅使用物理 wsdl 文件生成服務引用

[英]How to generate service reference with only physical wsdl file

我多年來一直在創建和使用 Web 服務,並且始終能夠使用 Visual Studio 從客戶端創建服務引用。 我有一個需要使用的第三方服務,他們拒絕打開他們的安全性,所以我可以看到 wsdl 並進行服務參考。 這是一項面向公眾的服務,所以我認為不需要這種級別的安全性,但它就是這樣。

我知道這是一個 n00b 問題,我很慚愧提出這個問題,但是當我可用的所有內容是客戶通過電子郵件發送給我的 wsdl 的物理副本時,我該如何在我的客戶中創建等效的服務參考信息? web.config 更改、SOAP 數據上的對象層等。就像使用自動服務引用一樣,我只想打開到服務的連接並開始將它與定義的對象一起使用。

據我所知,第三方服務不是 WCF,而是 SOAP。 順便說一句,我正在使用 VS 2010。 提前致謝,肯

這可能是最簡單的方法

  • 右鍵單擊該項目,然后選擇“添加服務引用...”
  • 在Address:框中,輸入已下載/已修改wsdl的物理路徑(C:\\ test \\ project ....)。
  • 打Go

有兩種方法可以解決這個問題。 您可以使用IDE生成WSDL,也可以通過命令行執行此操作。

1.通過IDE創建它:

在解決方案資源管理器窗格中,右鍵單擊要將服務添加到的項目:

在此輸入圖像描述

然后,您可以輸入服務WSDL的路徑並點擊go:

在此輸入圖像描述

2.通過命令行創建它:

打開VS 2010命令提示符(程序 - > Visual Studio 2010 - > Visual Studio工具)
然后執行:

WSDL /verbose C:\path\to\wsdl

然后,WSDL.exe將輸出.cs文件供您使用。

如果您在文件中收到了其他依賴項,例如xsd,請將它們添加到參數列表中:

WSDL /verbose C:\path\to\wsdl C:\path\to\some\xsd C:\path\to\some\xsd

如果你需要VB輸出,除了/verbose之外還要使用/language:VB

前輩展示了如何從本地文件導入,但您的 WSDL 將引用一個或多個 XSD 的可能性很小,並且您將收到錯誤消息:

WSDL 引用錯誤

您必須下載所有引用的 XSD 文件,並將它們放入與引用的 WSDL 相同的目錄中。 然后您必須手動編輯 WSDL,並將schemaLocation更改為本地下載的文件。

  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd0" namespace="http://tempuri.org/" />
      <xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
    </xsd:schema>
  </wsdl:types>

  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="tempuri.org.xsd" namespace="http://tempuri.org/" />
      <xsd:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.Arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
    </xsd:schema>
  </wsdl:types>

請注意,那些下載的 XSD 文件也有可能引用 Web 地址。

像這樣:

<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="http://gate.somesite.local:8084/Shop/DaxService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />

<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.Arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM