Skip to content

CloudyWing/HttpClientWebServiceSample

Repository files navigation

HttpClientWebServiceSample

這是一個使用 .NET 10 HttpClient 呼叫 ASMX SOAP WebService 的 demo。專案同時包含 .NET Framework 4.8.1 ASMX WebService 與 .NET 10 client,展示在不加入 Web Reference / Connected Service 的情境下手寫 SOAP 1.2 request。

對應筆記:使用 HttpClient 呼叫 WebService

文件

  • SPEC.md:demo 範圍、Solution / 專案檔規格、測試策略與 Demo 界線。
  • LICENSE.md:MIT 授權條款。

技術重點

  • Target Framework:.NET 10
  • WebService Server:ASP.NET WebService (.asmx) / .NET Framework 4.8.1
  • HTTP:HttpClient + IHttpClientFactory
  • XML:XmlSerializerXmlWriterXDocument
  • 測試:NUnit 4

專案組成

  • src/HttpClientWebServiceSample.Client:.NET 10 Console App,手寫 SOAP 1.2 request 呼叫 WebService,HttpClientIHttpClientFactory 管理。
  • src/HttpClientWebServiceSample.WebService:.NET Framework 4.8.1 ASMX WebService,提供 HelloWorld 方法與 WSDL,作為 demo 呼叫對象。
  • tests/HttpClientWebServiceSample.Client.Tests:NUnit 4 測試,涵蓋 envelope 組合、參數序列化、result 擷取與 HTTP 呼叫行為。

前置需求

  • Client 與測試專案:安裝 .NET 10 SDK 即可,跨平台可用。
  • WebService 專案:屬於 .NET Framework 4.8.1 的 ASP.NET Web Application,需在 Windows 安裝 Visual Studio(或含 ASP.NET 工作負載的 Build Tools)才能建置與啟動;Linux 或僅安裝 .NET SDK 的環境無法建置此專案。

建置與測試

整個方案的建置與測試需在上述 Windows + Visual Studio 環境執行:

dotnet build .\HttpClientWebServiceSample.slnx
dotnet test .\HttpClientWebServiceSample.slnx

若只想驗證 client 邏輯,可單獨建置與測試 client 專案,不需要 .NET Framework 環境:

dotnet test .\tests\HttpClientWebServiceSample.Client.Tests\HttpClientWebServiceSample.Client.Tests.csproj

啟動 ASMX WebService

瀏覽 WSDL 與執行 live 測試都需要先啟動 WebService。以 Visual Studio 開啟 HttpClientWebServiceSample.slnx,將 HttpClientWebServiceSample.WebService 設為起始專案後以 IIS Express 執行(F5)。啟動後可在瀏覽器開啟下列網址(實際 port 依 IIS Express 指定,以下為範例):

  • https://localhost:44399/TestWebService.asmx?WSDL:查看 WSDL。
  • https://localhost:44399/TestWebService.asmx?op=HelloWorld:查看 SOAP 1.1、SOAP 1.2 與 HTTP POST 格式。

Live WebService 測試

SoapClientLiveWebServiceTests 預設為 inconclusive,只有在設定 SOAP_SAMPLE_ENDPOINT 時才會實際呼叫執行中的 WebService。啟動 ASMX 專案後:

$env:SOAP_SAMPLE_ENDPOINT = "https://localhost:44399/TestWebService.asmx"
dotnet test .\HttpClientWebServiceSample.slnx

授權條款

本專案採用 MIT 授權條款

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors