47
Web Services In Native Code Nikola Dudar Program Manager Microsoft Corporation nikola.dudar@microso ft.com PC01

Nikola Dudar Program Manager Microsoft Corporation [email protected] PC01

Embed Size (px)

Citation preview

Web Services In Native Code

Nikola DudarProgram ManagerMicrosoft [email protected]

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

Web Services Refresher

Client Web Service

EndpointA B C

EndpointA B C

EndpointA B C

EndpointABC

Service Proxy

WSDL

XSDService HostCode

GeneratorCode

Generator

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

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

Building A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

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

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

Setting Channel Properties When Building A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

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

Setting Security Description In A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

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

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)

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>

Taking Advantage Of Serialization In A Client To WCF Service

Nikola DudarProgram ManagerWindows Web Services API

demo

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

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

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

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

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]

THANK YOU!

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]

© 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.

ADDITIONAL DETAILS

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)

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

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

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

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

Service Host Details

Runtime for hosting a service within a process

Endpoints must be defined before creating Service Host

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

Service Contract Details

Metadata for a service Table of callbacks that

implement service operations

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

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);

Listener Details

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

of channels ready to accept

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

Message Details

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

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

PERFORMANCE

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

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

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

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

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Please use the microphones provided

Q&A

© 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.