Create an Odata listener,
Then se how to fetch it with DataSVCUtil
Run you listener
Fetch
C:\Windows\Microsoft.NET\Framework\v4.0.30319\DataSvcUtil.exe /uri:http://localhost:8080/odata /out:HelloODataClient.cs /Version:1.0
Create an Odata listener,
Then se how to fetch it with DataSVCUtil
Run you listener
Fetch
C:\Windows\Microsoft.NET\Framework\v4.0.30319\DataSvcUtil.exe /uri:http://localhost:8080/odata /out:HelloODataClient.cs /Version:1.0
| # HelloOData.ps1 - Minimal OData Service | |
| $url = "http://localhost:8080/" | |
| $listener = New-Object System.Net.HttpListener | |
| $listener.Prefixes.Add($url) | |
| $listener.Start() | |
| Write-Host "OData service running at $url" | |
| Write-Host "Try: ${url}odata/`$metadata" | |
| Write-Host "Try: ${url}odata/Messages" | |
| Write-Host "Press Ctrl+C to stop" | |
| try { | |
| while ($listener.IsListening) { | |
| $context = $listener.GetContext() | |
| $request = $context.Request | |
| $response = $context.Response | |
| $path = $request.Url.AbsolutePath | |
| Write-Host "Request: $path" | |
| if ($path -eq "/odata/`$metadata") { | |
| # OData Metadata | |
| $metadata = @" | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"> | |
| <edmx:DataServices m:DataServiceVersion="2.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> | |
| <Schema Namespace="HelloOData" xmlns="http://schemas.microsoft.com/ado/2008/09/edm"> | |
| <EntityType Name="Message"> | |
| <Key> | |
| <PropertyRef Name="Id" /> | |
| </Key> | |
| <Property Name="Id" Type="Edm.Int32" Nullable="false" /> | |
| <Property Name="Text" Type="Edm.String" /> | |
| <Property Name="Timestamp" Type="Edm.DateTime" /> | |
| </EntityType> | |
| <EntityContainer Name="HelloODataContext" m:IsDefaultEntityContainer="true"> | |
| <EntitySet Name="Messages" EntityType="HelloOData.Message" /> | |
| </EntityContainer> | |
| </Schema> | |
| </edmx:DataServices> | |
| </edmx:Edmx> | |
| "@ | |
| $buffer = [System.Text.Encoding]::UTF8.GetBytes($metadata) | |
| $response.ContentType = "application/xml" | |
| $response.ContentLength64 = $buffer.Length | |
| $response.OutputStream.Write($buffer, 0, $buffer.Length) | |
| } | |
| elseif ($path -eq "/odata/Messages") { | |
| # Sample data | |
| $data = @" | |
| { | |
| "value": [ | |
| { | |
| "Id": 1, | |
| "Text": "Hello from OData!", | |
| "Timestamp": "2024-12-09T10:00:00Z" | |
| }, | |
| { | |
| "Id": 2, | |
| "Text": "Build system test", | |
| "Timestamp": "2024-12-09T11:00:00Z" | |
| } | |
| ] | |
| } | |
| "@ | |
| $buffer = [System.Text.Encoding]::UTF8.GetBytes($data) | |
| $response.ContentType = "application/json" | |
| $response.ContentLength64 = $buffer.Length | |
| $response.OutputStream.Write($buffer, 0, $buffer.Length) | |
| } | |
| else { | |
| # 404 | |
| $response.StatusCode = 404 | |
| $buffer = [System.Text.Encoding]::UTF8.GetBytes("Not Found") | |
| $response.OutputStream.Write($buffer, 0, $buffer.Length) | |
| } | |
| $response.Close() | |
| } | |
| } | |
| finally { | |
| $listener.Stop() | |
| Write-Host "`nService stopped" | |
| } |