-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
@page "/" | ||
@using BlazorGrpcWebCodeFirst.Shared; | ||
@using ProtoBuf.Grpc.Client; | ||
|
||
<h1>Hello, world!</h1> | ||
<EditForm Model="@request" OnValidSubmit="Submit"> | ||
<InputText @bind-Value="request.Text" /> | ||
<InputNumber @bind-Value="request.Value" /> | ||
<input type="submit" value="Submit" /> | ||
</EditForm> | ||
|
||
Welcome to your new app. | ||
@if (result != null) | ||
{ | ||
@result.NewText | ||
<br /> | ||
@result.NewValue | ||
<br /> | ||
} | ||
|
||
<SurveyPrompt Title="How is Blazor working for you?" /> | ||
@code | ||
{ | ||
MyServiceRequest request = new MyServiceRequest() { Text = "Hello world", Value = 42 }; | ||
MyServiceResult result; | ||
|
||
async Task Submit() | ||
{ | ||
var handler = new Grpc.Net.Client.Web.GrpcWebHandler(Grpc.Net.Client.Web.GrpcWebMode.GrpcWeb, new HttpClientHandler()); | ||
using (var channel = Grpc.Net.Client.GrpcChannel.ForAddress("https://localhost:44383/", new Grpc.Net.Client.GrpcChannelOptions() { HttpClient = new HttpClient(handler) })) | ||
{ | ||
var testFacade = channel.CreateGrpcService<IMyService>(); | ||
this.result = await testFacade.DoSomething(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using BlazorGrpcWebCodeFirst.Shared; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorGrpcWebCodeFirst.Server.Services | ||
{ | ||
public class MyService : IMyService | ||
{ | ||
public Task<MyServiceResult> DoSomething(MyServiceRequest request) | ||
{ | ||
return Task.FromResult(new MyServiceResult() | ||
{ | ||
NewText = request.Text + " from server", | ||
NewValue = request.Value + 1 | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
BlazorGrpcWebCodeFirst/Shared/BlazorGrpcWebCodeFirst.Shared.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.ServiceModel; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorGrpcWebCodeFirst.Shared | ||
{ | ||
[ServiceContract] | ||
public interface IMyService | ||
{ | ||
Task<MyServiceResult> DoSomething(MyServiceRequest request); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace BlazorGrpcWebCodeFirst.Shared | ||
{ | ||
[DataContract] | ||
public class MyServiceRequest | ||
{ | ||
[DataMember(Order = 1)] | ||
public string Text { get; set; } | ||
|
||
[DataMember(Order = 2)] | ||
public int Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace BlazorGrpcWebCodeFirst.Shared | ||
{ | ||
[DataContract] | ||
public class MyServiceResult | ||
{ | ||
[DataMember(Order = 1)] | ||
public string NewText { get; set; } | ||
|
||
[DataMember(Order = 2)] | ||
public int NewValue { get; set; } | ||
} | ||
} |