Using CoreWCF to unblock modernization of WCF apps | .NET Conf 2022
내용따라 한 것입니다.
visual Studio > 도구 > 명령줄> 개발자 명령 프롬프트 에서 대소문자 구분해서 아래 처럼 실행합니다.
C:\>dotnet new install CoreWCF.Templates
C:\>dotnet new corewcf -n SimpleServer
"CoreWCF Service" 템플릿이 성공적으로 생성되었습니다.
생성 후 작업 처리 중...
C:\SimpleServer\SimpleServer.csproj 복원 중:
복원할 프로젝트를 확인하는 중...
C:\SimpleServer\SimpleServer.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'h
ttp://nuget.grapecity.com/nuget'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
C:\SimpleServer\SimpleServer.csproj을(를) 2.76 sec 동안 복원했습니다.
복원에 성공했습니다.
C:\>cd SimpleServer.
C:\SimpleServer>start SimpleServer.csproj
하면 비쥬얼스투디오가 실행되면서 IService.cs 를 볼 수 있습니다.
0:00
>> Hi, I'm Sam Spencer. I am program manager.
0:03
I'm here with Matt Connew and we're going to talk about using
0:06
coreWCF to unblock modernization of WCF apps.
0:10
What is CoreWCF?
0:12
Well, the elevator pitch is that it's
난데없이 영어공부를 다하네요
엘리베이터 피치란 어떤 상품, 서비스 혹은 기업과 그 가치에 대한 빠르고 간단한 요약 설명이다. 로켓 피치라고도 한다. 엘리베이터 피치라는 이름은 엘리베이터에서 중요한 사람을 만났을 때 자신의 생각을 요약하여 20초에서 3분이라는 짧은 시간에 전달할 수 있어야 한다는 의미로 지어졌다.
0:14
an open-source wire format compatible port of WCF server to.NET.
0:19
That's quite a mouthful, so let's break that down.
한번에 다 말할수 없으니 나눠서 쪼개서 해봅시다.
0:22
WCF is Windows Communication Foundation.
0:26
It's an RPC mechanism that was introduced
0:29
in.NET Framework 3 in 2006,
0:34
and it enables you to make cross-process calls in.Net.
0:37
WCF is wire format compatible,
0:40
so we use the same soap and binary XML protocols.
0:43
We are a port to modern.NET technologies.
0:47
We're compatible with WCF,
0:48
but we're not just a direct or recompile.
0:51
So when now implemented as ASP.NET core middleware.
0:54
You get to take advantage of all it's in
0:57
ASP.NET and we work with modern.NET
1:00
technologies such as async and await,
1:03
dependency injection, I logger, etc.
1:07
We report to.NET.
1:09
We work with.NET Core.NET 5, 6, and 7.
1:12
Also in.NET framework and we'll talk
1:14
more about the significance of that later.
1:16
Because we work in.NET,
1:19
we also work anywhere the.NET
1:20
works including Linux and Containers.
1:22
You can now use WCF in containers in the Cloud.
1:27
We're open source projects.
1:30
We have contributors from around the world,
1:32
including Microsoft employees, and we also have Microsoft support.
1:36
We have a number of large customers who depend
1:39
on being able to call when they have production issues.
1:43
Matt, can you do a demo of CoreWCF for us?
1:47
>> Yes, I can. I have to apologize for
1:48
weird size of my screen Windows just
1:51
decided to shrink the screen down to a really tiny screen.
1:57
We'll do the best we can with it.
2:00
We've actually shipped some templates for coreWCF.
2:04
Today I'm going to create a WCF service
2:07
and a client to communicate with it.
2:10
First thing we need to do is install the new coreWCF template.
2:22
We do that by installing the coreWCF templates package.
2:30
Then after we create,
2:34
we can create two projects,
2:36
one's going to be using a coreWCF project,
2:38
which will create us a server.
2:40
It's just going to go out simple server.
2:43
Then again create a second application,
2:46
which is going to be a console app,
2:48
which will generate the client to communicate with our service.
3:01
First we're going to our simple service
3:04
and I'll open up the project.
3:11
I'll see how Visual Studio does on a tiny little screen.
3:21
First thing we're going to look at is a service contract.
3:28
Let's open up, clean things up a
3:33
little to make it usable as best we can.
3:44
Here we have, those familiar with WCF,
3:49
will recognize a service contract.
3:51
With WCF, you have a service contract which
3:55
is an interface which defines all your methods,
3:59
and then you have every method which you want to expose.
4:01
You put an oppression contract attribute on that method.
4:08
This is actually identical of a namespace
4:12
to what you'd get if you're using a classic,.NET Framework,
4:15
WCF templates and Visual Studio.
4:20
Now let's launch this App.
4:36
I just want to find the output window for this. Here we go.
4:44
We've actually got our metadata,
4:47
which is [inaudible] service,
4:49
which I'll show you in a minute,
4:50
is exposed at this URL and we click on through on here.
4:59
Because page, this is the service helper page for the metadata,
5:05
which is actually identical to what you would get on WCF.
5:08
If you're running on.Net Framework.
5:09
We kept this absolutely identical in the content because there are
5:14
some customers who they use
5:17
this page as a keep-alive ping check against the service.
5:21
If the content changes,
5:23
it could break some tooling.
5:25
We've kept it as identical as we possibly can on a wide level.
5:30
We can actually check out the Worstall,
5:33
which is an XML document which describes a service.
5:36
We're going to copy this into clipboard because
5:38
we'll use it again in a minute.
5:41
Now let's go back to Client App
5:48
and that in Visual Studio.
6:00
Let me suggest the regular Hello World console app.
6:04
Right now there's nothing in
6:06
there other than a console. WriteLine Hello World.
6:12
What we need to do is we need to add a reference to our Service.
6:17
Again, say we're going to Add connected service.
6:22
We're going to choose to add a WCF service.
6:30
>> This is exactly the same experience in
6:33
coreWCF that you have with WCF?
6:36
>> Yes. This is going to generate into application,
6:43
the service client implementation,
6:49
which I'll show you in a minute.
6:51
It'll have all the exact same interfaces and
6:53
everything that is actually in your service.
6:56
If you go to solution explorer and look at the implementation,
7:05
you'll see that we've got the same CompositeType that we had.
7:10
We've got the same IService,
7:13
with the same methods.
7:15
There's a little bit more verbosity in the attributes.
7:21
It's explicitly putting values in which you
7:24
normally implicitly done on the server side.
7:27
But this is identical to what you see on the server-side.
7:32
Now if we go to Program,
7:33
we can actually call the service. Let's run it.
7:42
We've still got the server running in the other instance of
7:44
VS. You'll see hello,
7:48
says you entered 42,
7:50
which is what default application
7:53
does is it takes in an integer and just returns a string.
7:56
You entered and the number that you sent.
7:58
You see our services up and running,
8:02
can get your basic service up and running.
8:04
But we've done a little bit more in coreWCF.
8:07
We've actually embraced a new way
8:12
of doing things and we've got
8:14
a whole bunch of DI capability in here now.
8:17
What we can do is we can go to our program and
8:23
add into DI our service type.
8:32
Now coreWCF,
8:34
will check DI first to see if it's exists in
8:37
DI and will return us a real instance of DI.
8:41
What this allows us to do is now have dependencies
8:46
being passed in to our service via a constructor.
8:53
That's my code snippets,
8:56
it's not showing in my code snippets.
8:58
>> Toolbox. View toolbox.
9:02
>> Is under view?
9:03
>> Yeah.
9:08
>> Nope. This is the last one.
9:11
Another soft top my head.
9:13
I can just put private ILogger of service. Here is my logger.
9:23
Then I can add
9:29
a constructor for my service,
9:35
which takes an ILogger of service.
9:40
Then just set logger to that logger.
9:46
Then in code here,
9:49
we can do logger.LogInformation.
10:03
This is now using ASP.NET Core as login
10:06
together with any implementation of WCF service.
10:10
>> Yeah.
10:10
>> Pretty good integration between
10:13
modern technology and stuff from awhile ago.
10:15
>> Oh, the reason why
10:17
toolbox isn't working is because the process was still running.
10:21
Now if I come to my online to launch it,
10:31
because we want to be able to easily get up the console output.
10:39
Then we come to a Client and run that.
10:51
We will now see that we've got the log output on
10:54
here saying that you entered 42. That's the log out.
10:57
>> Sweet.
10:57
>> That's has gotten injected into
10:59
our service. But we didn't stop there.
11:02
We had to look at what was happening on
11:04
Web API and why they hold in things.
11:07
Well, you can inject parameters
11:09
into your controller methods there.
11:13
Well, that's a good trick to do so we'll copy it.
11:16
That's exactly what we did.
11:18
Now, there is a small bug in
11:21
the current templates where it doesn't add a required package.
11:27
We're just going to do dotnet add package coreWCF.Primitives.
11:35
This is needed because we have the code behind
11:37
piece and it lives inside of this package.
11:40
The template only adds coreWCF.HTTP,
11:42
which is perfectly fine if you
11:44
just want to use a vanilla scenario.
11:46
But you need to explicitly add primitives to get
11:48
the code generator to work.
11:50
Then once you've got that added,
11:54
then there's two things you need to do.
11:55
First thing you need to do is make your class partial.
12:08
Then you can inject into your operation.
12:17
You just need to add system text.
12:23
You can see here that we
12:27
GetData method now we've added two new parameters records,
12:30
which are attributed with injected attribute,
12:33
that's over HttpResponse and HttpRequest.
12:36
Now these two, along with,
12:38
we also support HB context special case
12:41
because they're not evident directly come from DI normally.
12:45
But any type which is int here, you can add in air.
12:49
Now reason why we had to add the partial key word is because
12:53
this method with these two new parameters
12:55
no longer matches our interface method.
12:57
Because your interface still only has one parameter on it.
13:00
What we do behind the scenes is we regenerate for
13:03
missing method to match the contract.
13:07
In there we then go and pull the items of DI and call
13:10
your new injected method implementation.
13:15
Now if we save that and
13:18
then what we're doing here is we're
13:21
just outputting all the heads via a StringBuilder,
13:23
so it's just a single log.
13:26
Now when we do.netrun,
13:35
then when we run the client, when we go back to serve,
13:40
if everything has worked correctly,
13:42
there is a HTTP header is now being output in the logs.
13:46
We can see that we got
13:47
the HTTP request objects with its headers via
13:50
injection and didn't need to do
13:52
any typically complicated code to be able to get access to it.
13:56
>> Sweet.
13:57
>> There's one more trick that we have got.
14:02
If you look the interface,
14:05
it's the attributes of coreWCF namespace.
14:11
We've got some feedback from a customer saying,
14:14
"But I have code which is shared between the client and
14:17
the server and my client is in system service model."
14:21
If you add the system serves
14:24
model primitives client package to your project,
14:28
you can actually use the system service model attributes instead,
14:31
and it works just exactly the same.
14:33
>> Great. Let's talk about what is included in coreWCF.
14:38
What's available now is the service definition
14:41
using interface contracts, which Matthew showed.
14:44
He also showed the WSDL of a client generation.
14:46
You have exactly the same experience
14:48
as you would with.NET Framework.
14:50
We have the set of basic bindings.
14:52
We have partial support for XML configuration.
14:55
WCF was very configuration happy.
14:58
We can pass many of the attributes from
15:02
those conflict files to setup the configuration,
15:06
and we have the most extensibility APIs.
15:10
What's coming soon is integration
15:13
with ASP.NET authentication stack.
15:16
You can then use JWT and other modern authentication schemes.
15:20
The top request you've had from customers is named pipe binding,
15:24
which is for local communication
15:28
between individual services because that is Windows specific.
15:31
We'll also be doing Unix domain sockets,
15:34
which works on Linux and modern versions of Windows Server.
15:39
Another customer request is message queue.
15:42
Again, we're being abstract here.
15:44
We're enabling a provide
15:46
a model so you can plug in different message queues.
15:49
I can work with Azure, RabbitMQ, etc.
15:52
Then lastly, reliable session's.
15:55
Showing this visually, this is
15:58
the classic architecture diagram for WCF.
16:01
If you search for WCF architecture,
16:04
you'll get this diagram.
16:05
But it's a good way to show what support we have.
16:08
Everything in contracts is supported in coreWCF.
16:12
In the service runtime,
16:13
we have everything apart from transactions.
16:15
That's because.NET Core doesn't have
16:18
the same transaction support that was in.NET Framework.
16:22
From a messaging level, again,
16:24
we're missing the transactions and then named pipes,
16:27
MSMQ that I just talked about.
16:30
Then activation and hosting,
16:32
that is where everything has fundamentally changed because
16:34
we've re-implemented as ASP.NET middleware.
16:38
We can run anywhere ASP.NET Core can run.
16:42
If you want to do is do a console app,
16:43
you can just do a console app.
16:45
If you want to be a Windows service,
16:47
use iOS, etc, we work in all those.
16:51
>> The title let's talk was how the hell
16:54
CoreWCF makes it easier to modernize applications.
16:58
We know customers have a large investment in
17:00
WCF and that was one of the factors that was making it
17:03
hard for me to move from.Net Framework to Core or.Net.
17:08
CoreWCF gives you a much easier way to port those services.
17:13
All the service implementation is exactly the same.
17:15
It's just the ceremony about how you
17:18
instantiate and exposes services that's changed.
17:21
Your API contracts, those move across unchanged.
17:24
XML configuration we talked about.
17:27
The other cool thing is we support CoreWCF on.Net Framework.
17:31
If you've got a large app with many services,
17:34
what you can do is migrate
17:35
individual services at a time while on.Net Framework,
17:38
keep that application running.
17:40
Then once you've done all those ports and you're ready,
17:44
you can then flip the framework underneath
17:46
and it's much easier to do in one go.
17:49
But the other cool thing is
17:51
the previous talk was talking about the upgrade assistant
17:53
and we have support now in the upgrade assistant for WCF apps.
17:57
Matt, can you give a demo of using the upgraded system with WCF?
18:01
>> Yes, certainly. Here again on my tiny little screen,
18:05
we have a basic calculator service.
18:09
It's got few add, subtract, multiply,
18:12
divide methods with the implantation
18:14
and the main bulk and the main method,
18:20
creates a new service host and opens it
18:22
and it gets all of its config from the app config file.
18:28
This is where via an app config or web config,
18:32
you can specify all the information
18:35
you need to know about your service,
18:36
what endpoint you're listening on,
18:38
URLs, behaviors, that sort of thing.
18:41
This is what a.Net Framework application looks like.
18:45
If we're going to upgrade it, first of all,
18:48
let's have a look at it running.
18:54
Let's get the service running,
18:58
simple as that, and run the client,
19:01
and see if the client
19:02
sends four different operations to the service
19:05
and tells you what
19:08
the answer is based on what the service have turned.
19:11
We can see on the service side,
19:12
we also emit a console right line
19:16
saying all the things which have been asked to us.
19:25
Let's upgrade this application.
19:28
Actually, before we do that there's one thing I meant to do,
19:34
and that is to go and get the wizdl format.
19:40
This is from the existing service
19:42
and just like in our previous demo,
19:45
you can click through and find out what was neg or what was overt.
19:50
Now let's convert this service.
19:54
First thing we need to do is we actually need to
19:56
install the upgrade assistant.
19:59
Says dotnet tool, install,
20:02
minus g it's a global tool, upgrade assistant.
20:10
I was going to download and install the global tool,
20:13
and for those who don't know it means
20:15
that you can launch it from anywhere,
20:17
not just inside a repo that you're using.
20:20
Now we've got that.
20:23
We're going to launch upgrade assistant.
20:32
I'm going to say upgrade and we can pass the solution file.
20:37
Once we've launched that,
20:41
first question is going to ask us is,
20:43
which project do we wish to be converting?
20:49
Just need to wait little bit more. Here we go.
20:52
The first step is
20:55
which entry point or which project is one to convert.
21:00
We're going to say we're going to convert calculator service.
21:06
>> This is where you press "Enter" a lot, right?
21:09
>> Yeah. I think it was 12 times.
21:11
There's a whole bunch of steps
21:12
and we get CoreWCF step after I think.
21:21
Where are we on this? Now we're back at step number 4,
21:25
we'll see that step number 7 is one that we want.
21:28
It's going to take a few more.
21:33
Here we are. We're at update WCF service.
21:36
We go look at what our projects like so far.
21:40
Address point is being converted to a SDK application.
21:47
But if you look for code,
21:49
it's still the same but it won't compile now because
21:52
things like service host aren't available anymore.
21:55
Let's just finish off the upgrade.
22:04
A few more enters.
22:06
I've been told that they're planning on
22:09
making a little bit less verbose on stepping through.
22:13
>> I think you need the one with
22:14
little rocking [inaudible] things.
22:17
>> That would work too. Now it's being converted.
22:23
Let's see what is done for us.
22:26
We still got our service contract.
22:28
But if you look now it's in the CoreWCF namespace.
22:32
Then if you go look at start-up,
22:35
this code has completely changed.
22:37
There's replacement of a code with all the code needed to
22:39
start the application using ASP.NET Core.
22:44
You have your new APIs there.
22:47
If we go look at our app config,
22:51
you'll see that what's left in there is a comment saying,
22:55
everything's moved to a new file,
22:56
reason being there might be other config stuff in
22:59
there for other aspects of your app.
23:01
We don't want to talk about. If we go look at the WCF config,
23:06
some of it has been ported across and the things which we don't
23:09
support have been commented out,
23:13
being left in there, but commented out with a comment
23:15
about what's going on with it.
23:28
Actually, there's couple of bugs
23:31
in the way of having to deal with right now.
23:35
One of them is,
23:37
and I don't think this is related to the [inaudible] piece,
23:39
there's a assembly info file which we'll just delete.
23:44
It's got some stuff in it which isn't supported on.NET 7.
23:50
The other problem is,
23:53
it's not using registrations of our packages.
23:56
That will break the wizdl side of things.
24:06
>> This is all because we just released.NET 7, right?
24:09
>> Yeah. We got rid of the older versions.
24:21
Then we should be able to run the app now.
24:30
See what I did. It's running now.
24:38
We can actually go and look at it.
24:45
This is a service I am now
24:48
running on the ASP.NET Core with CoreWCF.
24:51
>> Great. Call-to-action,
24:56
we're a open-source project,
24:58
our repo is listed here.
25:00
The project templates that Matt showed, I have listed,
25:03
the NuGet packages, the upgrade assistant.
25:06
We have a blog with our announcements
25:08
and a monthly community stand up.
25:10
If you want to come ask questions,
25:12
see what's going on with the project,
25:13
you want to contribute, we'd love to see you there.
25:15
Thank you very much.
'VB.NET&MSSQL' 카테고리의 다른 글
라즈베리파이에서 vb.net exe 실행하기 (0) | 2023.03.21 |
---|---|
라즈베리 파이 원격 접속 (0) | 2023.03.21 |
HRESULT: 0x800A03EC (1) | 2022.07.20 |
MSSQL DATAFILE 위치변경 (0) | 2021.12.29 |
[MSSQL] 숫자인지 문자인지 확인 (0) | 2021.10.16 |
댓글