Top Banner
Web Services In Native Code Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microso ft.com PC01
47
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Web Services In Native Code

Nikola DudarProgram ManagerMicrosoft [email protected]

PC01

Page 2: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Windows Web Services API

Connecting native code and web services Win32 API No dependency on .Net Framework

Interoperability with WS-* SOAP stacks Windows Communication Foundation (WCF) ASP .Net XML Web Services (ASMX) Non-Microsoft stacks

System Component of Windows 7 Available for Windows XP/Vista/2003/2008

Page 3: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Web Services Refresher

Client Web Service

EndpointA B C

EndpointA B C

EndpointA B C

EndpointABC

Service Proxy

WSDL

XSDService HostCode

GeneratorCode

Generator

Page 4: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Windows Web Services API Layers

Your Application Code

Network I/O

Service Model

Channel Layer

XML Layer

Erro

rs

Hea

p

Asyn

c C

onte

xt

Page 5: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Service Model

Automatically manages communication Service Proxy on client Service Host on service

Message exchanges as function calls Client calls generated function Server implements callback

Driven from Contract WsUtil.exe generates C code from WSDL/XSD

Page 6: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Building A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

Page 7: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Windows Web Services API

Your Application Code

Network I/O

Service Model

Channel Layer

XML Layer

Erro

rs

Hea

p

Asyn

c C

onte

xt

Page 8: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Channel Layer

Full control over communication Message

Data sent or received Consists of body and headers

Channel Abstraction for message exchange protocol Unified API for all transports (HTTP, TCP, UDP) Properties to tweak different settings

Page 9: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Setting Channel Properties When Building A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

Page 10: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Security Description

Securing message exchange on the channel Transport security

HTTP: SSL TCP: Windows SSPI

Message plus Transport security (Mixed Mode) Username/Password, Kerberos APREQ,

XML Token, Secure Conversation Token Basic support for SAML and federation

No support for Full message security mode

Page 11: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Setting Security Description In A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

Page 12: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Windows Web Services API

Your Application Code

Network I/O

Service Model

Channel Layer

XML Layer

Erro

rs

Hea

p

Asyn

c C

onte

xt

Page 13: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

XML Layer

Full access to content of messages Unified API for all encodings

Text, Binary, MTOM SOAP subset of XML 1.0 (No DTD) XmlBuffer

In-memory store for XML data XmlReader and XmlWriter

Forward only access Integrated canonicalization (C14n)

Page 14: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Serialization

Mapping C data types to/from XML types WsUtil.exe can generate C types from XSD

struct PurchaseOrder{ int id;};

<PurchaseOrder> <id>123</id></PurchaseOrder>

Page 15: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Taking Advantage Of Serialization In A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

Page 16: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Windows Web Services API

Your Application Code

Network I/O

Service Model

Channel Layer

XML Layer

Erro

rs

Hea

p

Asyn

c C

onte

xt

Page 17: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Supported Configurations

Transports HTTP, TCP, UDP

XML Encodings Text, Binary, and MTOM

Envelope SOAP 1.1 and 1.2

Addressing WS-Addressing 0.9 and 1.0

Metadata WSDL 1.1, XML Schema 1.0 WS-MetadataExchange 1.1 WS-Transfer March 2006

Security WS-Security 1.0 and 1.1

(partial) WS-Trust February 2005 and

1.3 (partial) WS-SecureConversation 1.1

and 1.3 (partial) Policy

WS-Policy from March 2006 and v.1.2

WS-Policy Attachment from March 2006 and 1.2

WS-SecurityPolicy 1.1

Page 18: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Getting Started With WWSAPI

PDC 2008 build of Windows 7 Webservices.Dll in System32

PDC 2008 build of Windows SDK Wsutil.exe Webservices.h and webservices.lib Documentation with samples

Windows XP/Vista/2003/2008? Wait for system update

around Windows 7 Beta

Page 19: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Additional Resources

Technical details Slides 25 -45 Documentation in Windows SDK

Related talks and Hands on Labs PCHOL12: Windows Web Services API PC26: Building Applications with MFC

Page 20: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Additional Resources

Networking Developer Center on MSDN http://msdn.microsoft.com/network/

Connect https://connect.microsoft.com/wndp/

Blogs http://blogs.msdn.com/nikolad/ http://blogs.msdn.com/haoxu/ http://blogs.msdn.com/wndp/

Email [email protected]

Page 21: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

THANK YOU!

Page 22: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Questions?

Networking Developer Center on MSDN http://msdn.microsoft.com/network/

Connect https://connect.microsoft.com/wndp/

Blogs http://blogs.msdn.com/nikolad/ http://blogs.msdn.com/haoxu/ http://blogs.msdn.com/wndp/

Email [email protected]

Page 23: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 24: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

ADDITIONAL DETAILS

Page 25: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

WWSAPI And WCF

WWSAPI is peer to WCF Use WCF in managed code Use WWSAPI in native code

Similar programming models XML, Message, Channels (message-oriented) Service Model (function-oriented)

Page 26: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Cross Layer Functionality

Error object Stores information on root cause of an error Also used in reporting SOAP faults

Heap Internal storage when

messages sent and received Simplifies error prone "Alloc/Free" pattern

Async Context Enables asynchronous requests

Page 27: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Error Handling Details

Most functions return HRESULTs Most functions have an optional

WS_ERROR* parameter Set of property values Zero or more error strings

Reset error object after an error occurred Also used for reporting SOAP faults

Page 28: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Heap Details

Specialized allocation pattern Simplifies error prone "Alloc/Free" pattern Accumulated allocation, free all at one

WS_HEAP* heap;WsCreateHeap(INFINITE, 0, &heap, error);

for (...){ Data* data; WsAlloc(heap, sizeof(Data), &data, error); WsAlloc(heap, sizeof(Data), &data, error); WsResetHeap(heap);}

WsFreeHeap(heap);

Frees all allocations

Page 29: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Service Proxy Details

Client side proxy for a service Creating Service Proxy requires

Channel Type Channel Binding Service properties (optional) Security description (optional)

Opening Service Proxy requires target URL Many operations can be called on opened

proxy Reset and re-use after close

Page 30: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Service Host Details

Runtime for hosting a service within a process

Endpoints must be defined before creating Service Host

Page 31: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Service Endpoint Details

Many endpoints allowed per one Service Host

Endpoint is URI on which it is hosted Channel type Channel binding Security description Service contract Authorization callback Endpoint properties

Page 32: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Service Contract Details

Metadata for a service Table of callbacks that

implement service operations

Page 33: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Channels Details

Channel Type Direction and session

information for a channel Channel Binding

Transfer protocol Security description

How to secure transfer Channel properties

Additional optional settings

Page 34: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Channel Properties Details

Properties can be set on channel creation WS_PROPERTY parameter to WsCreateChannel

Properties can be changed after channel is created WsSetChannelProperty

Properties can be retrieved WsGetChannelProperty

ULONG timeout = 1000; // 1 second

WS_PROPERTY properties[1];properties[0].id = WS_CHANNEL_PROPERTY_SEND_TIMEOUT;properties[0].value = &timeout;properties[0].size = sizeof(timeout);

WsCreateChannel(WS_CHANNEL_TYPE_DUPLEX_SESSION, WS_CHANNEL_BINDING_TCP, &properties, 1, &securityDescription, &channel, error);

WsSetChannelProperty(channel, WS_CHANNEL_PROPERTY_SEND_TIMEOUT, &timeout, sizeof(timeout), error);

Page 35: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Listener Details

Service side object that creates channels Server can accept channels from the Listener Listeners maintains queue

of channels ready to accept

Page 36: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Channel Security Details

Specified when creating a channel Transport security

HTTP: SSL, Header auth: Basic/Digest/SPNEGO/NTLM

TCP: Windows SSPI Message security

Username/Password, Kerberos APREQ, XML Token

Secure Conversation support Basic support for SAML and federation

Page 37: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Message Details

Encapsulates data transmitted or received Can be used without a channel Headers buffered in memory Body is streamed Properties specify optional settings

Page 38: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Asynchronous Execution Details

Passing non-NULL WS_ASYNC_CONTEXT to functions allows asynchronous execution

Function return value indicates asynchronous completion Callback is invoked to signal completion

Page 39: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

PERFORMANCE

Page 40: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Performance – Memory

RPC Sapphire WCF0

1000

2000

3000

4000

5000

6000

Client Private Working Set (Kb) – Steady State

Client Private Working Set (Kb)

TCP/Binary

WWSAPI Message Sizes (bytes) Request: 153; Reply: 89

Configuration:Server: 2.2 GHz AMD (dual core), 64-bit Windows Server 2008Clients: 2.6 GHz AMD (dual core), 64-bit Windows Vista SP1

WWSAPI

Page 41: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Performance – Memory

RPC Sapphire WCF0

1000

2000

3000

4000

5000

6000

7000

Server Private Working Set (Kb) – Steady State

Server Private Working Set (Kb)

Configuration:Server: 2.2 GHz AMD (dual core), 64-bit Windows Server 2008Clients: 2.6 GHz AMD (dual core), 64-bit Windows Vista SP1

TCP/Binary

WWSAPI Message Sizes (bytes) Request: 153; Reply: 89

WWSAPI

Page 42: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Performance – TCP Throughput

RPC Sapphire WCF0

10000

20000

30000

40000

50000

60000

70000

80000TCP Server Throughput (operations/sec)

TCP Server Throughput (Operations per sec)

Configuration:Server: 2.2 GHz AMD (dual core), 64-bit Windows Server 2008Clients: 2.6 GHz AMD (dual core), 64-bit Windows Vista SP1

TCP/Binary

WWSAPI Message Sizes (bytes) Request: 153; Reply: 89

CPU Utilization > 98%

WWSAPI

Page 43: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Performance – HTTP Throughput

RPC Sapphire WCF0

2000

4000

6000

8000

10000

12000

14000

16000

18000HTTP Server Throughput (operations/sec)

HTTP Server Throughput 2-proc

Configuration:Server: 2.2 GHz AMD (dual core), 64-bit Windows Server 2008Clients: 2.6 GHz AMD (dual core), 64-bit Windows Vista SP1

CPU Utilization > 96%Self-hosted WCF and WWSAPI

HTTP/UTF8

WWSAPI

Page 44: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Page 45: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

Please use the microphones provided

Q&A

Page 46: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 47: Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microsoft.com PC01.