CQ-CSER

web设计开发爱好者

WCF学习笔记1

Posted on | 三月 16, 2010 | No Comments

载自《programing in wcf 2nd》

wcf

In the past, distributed computing technologies such as DCOM and .NET Remoting aspired to provide the same programming model to the client regardless of whether the object was local or remote. In the case of a local call, the client used a direct reference, and when dealing with a remote object, the client used a proxy. The problem with trying to use the local programming model as the remote programming model was that there is much more to a remote call than an object with a wire. Complex issues such as lifecycle management, reliability, state management, and security raised their heads, making the remote programming model significantly more complex. Numerous problems arose, all because the remote object was trying to be what it is not—a local object.

WCF also strives to provide the client with the same programming model regardless of the location of the service. However, the WCF approach is the exact opposite: it takes the remote programming model of instantiating and using a proxy and uses it even in the most local case. Because all interactions are done via a proxy, requiring the same configuration and hosting, WCF maintains the same programming model for the local and remote cases; thus, it not only enables you to switch locations without affecting the client, but also significantly simplifies the application programming model.

WCF supports the following transport schemas:

  • HTTP
  • TCP
  • Peer network
  • IPC (Inter-Process Communication)
  • MSMQ

Addresses always have the following format:

[base address]/[optional URI]

 

The base address is always in this format:

[transport]://[machine or domain][:optional port]

 

Here are a few sample addresses:

http://localhost:8001

http://localhost:8001/MyService

net.tcp://localhost:8002/MyService
net.pipe://localhost/MyPipe
net.msmq://localhost/private/MyQueue
net.msmq://localhost/MyQueue

 

The way to read an address such as this:

http://localhost:8001

 

is like this: “Using HTTP, go to the machine called localhost, where on port 8001 someone is waiting for my calls.”

If there is also a URI, as in:

http://localhost:8001/MyService

 

the address will read as follows: “Using HTTP, go to the machine called localhost, where on port 8001 someone called MyService is waiting for my calls.”

1.3.1. TCP Addresses

TCP addresses use net.tcp for transport and typically include a port number, as in:

net.tcp://localhost:8002/MyService

 

When a port number is not specified, the TCP address defaults to port 808:

net.tcp://localhost/MyService

 

It is possible for two TCP addresses (from the same host, as discussed later in this chapter) to share a port:

net.tcp://localhost:8002/MyService
net.tcp://localhost:8002/MyOtherService

1.3.2. HTTP Addresses

HTTP addresses use http for transport, and can also use https for secure transport. You typically use HTTP addresses with outward-facing Internet-based services, and you can specify a port as shown here:

http://localhost:8001

 

When the port number is unspecified, it defaults to 80 (and port 443 for HTTPS). As with TCP addresses, two HTTP addresses from the same host can share a port, even on the same machine.

HTTP-based addresses are also used throughout this book.

1.3.3. IPC Addresses

IPC addresses use net.pipe for transport, to indicate the use of the Windows named pipe mechanism. In WCF, services that use IPC can only accept calls from the same machine. Consequently, you must specify either the explicit local machine name or localhost for the machine name, followed by a unique string for the pipe name:

net.pipe://localhost/MyPipe

 

You can open a named pipe only once per machine, so it is not possible for two named pipe addresses to share a pipe name on the same machine.

IPC-based addresses are used throughout this book.

1.3.4. MSMQ Addresses

MSMQ addresses use net.msmq for transport, to indicate the use of the Microsoft Message Queue (MSMQ). You must specify the queue name. When you’re dealing with private queues you must also specify the queue type, but that can be omitted for public queues:

net.msmq://localhost/private/MyService
net.msmq://localhost/MyService

 

Chapter 9 is dedicated to making queued calls.

1.3.5. Peer Network Addresses

Peer network addresses use net.p2p for transport, to indicate the use of the Windows peer network transport. You must specify the peer network name as well as a unique path and port. Using and configuring peer networks is beyond the scope of this book, and you will see very little mention of peer networks in subsequent chapters. In most cases, a desire to use a peer network actually indicates a need for the publish-subscribe pattern. Appendix C presents my helper framework for this pattern.

终于明白前面的『』是做什么的了。哎

相关文章:

  1. wcf学习笔记2

评论|Comments

留言|Leave a Reply





  • 微波:

    既然要赌,就要赌到底,玩命才会WIN
  • SUNSHINE

  • About

    本博客采用创作共用版权协议,要求署名、非商业用途和保持一致. 转载本博客内容也遵循“署名-非商业用途-保持一致”的创作共用协议.

    订阅

    Search

    Admin