Nginx cluster-WCF distributed LAN application, nginx cluster wcf
Directory
1 General idea... 1
2 Nginx cluster WCF distributed LAN structure... 1
3. About BasicHttpBinding. 1
4. Compile the WCF Service and client program... 2
5 URL reserved items... 6
6. Deploy the WCF Service Program to three PCs in the LAN... 7
7. Nginx cluster configuration and setup... 8
8. Start the WCF client program... 10
9 Conclusion... 11
1. General idea
L Nginx cluster WCF distributed LAN Structure
L about the BasicHttpBinding of WCF
L compile the WCF Service and client programs
L URL reserved items
L deploy the WCF Service Program to three PCs in the LAN
L Nginx cluster configuration and Setup
L start the WCF client program
L Summary
2 Nginx cluster WCF distributed LAN Structure
About WCF, you can either host IIS or yourself. This article uses the self-boarding mode. In many special scenarios, such as downloading large files (such as several hundred MB and 1 GB), images, and documents, if IIS is used as the host, insufficient memory may be generated. So here we use the self-hosting method as an example.
In addition to reverse proxy, the Nginx cluster can be applied to it. In terms of WCF processing, it also performs well. The following figure shows the distributed design structure of Nginx clusters in WCF:
3. About BasicHttpBinding of WCF
First, understand the support of the system pre-defined binding for different security modes. For details, refer to the following article:
[WCF Security Series] binding, security mode, and client credential type: Summary
Https://www.cnblogs.com/artech/archive/2011/05/28/Authentication_034.html
- All bindings can adopt no secure transmission mechanism, that is, None safe mode is supported;
- The default BasicHttpBinding mode is None, the WS-related binding mode is Message, and the LAN-related binding mode is Transport;
- Except NetNamedPipeBinding, all bindings support Message security mode;
- All bindings that support Message mode support the Mixed mode except NetMsmqBinding;
- Except WSDualHttpBinding, all bindings support the Transport mode;
- Only BasicHttpBinding supports the TransportCredentialOnly mode;
- Only NetMsmqBinding supports the Both security mode.
Here, the Ningx cluster of WCF mainly uses BasicHttpBinding. Indicates a binding. The Windows Communication Foundation (WCF) service can use this binding configuration to publish such endpoints: these endpoints can communicate with ASMX-based Web Services and clients and other services that comply with the WS-I Basic Profile 1.1 Standard.
4. Compile the WCF Service and client programs
L The main directory of the solution is as follows:
L WCF Service Program
IOutputSomething. cs
using System.ServiceModel;namespace Service.Interface{ [ServiceContract] public interface IOutputSomething { [OperationContract] string GetContentData(int i); [OperationContract] string GetIpAddress(); }}
OutputSomething. cs
Using Service. interface; using System. net; using System. serviceModel; namespace Service {[ServiceBehavior (ConcurrencyMode = ConcurrencyMode. multiple)] public class OutputSomething: IOutputSomething {// <summary> // name // </summary> string threadNumber; readonly object thisLocak = new object (); public string GetContentData (int I) {lock (thisLocak) {threadNumber = I. toString () + "-" + "I Am a host:" + GetIpAddress ();} return string. format ("serial number {0}, thread number {1}", I, threadNumber);} public string GetIpAddress () {string AddressIP = string. empty; foreach (IPAddress _ IPAddress in Dns. getHostEntry (Dns. getHostName ()). addressList) {if (_ IPAddress. addressFamily. toString () = "InterNetwork") {AddressIP = _ IPAddress. toString () ;}} return AddressIP ;}}}
Program. cs
Using Service; using System. serviceModel; namespace HighlyConcurrentHosting {class Program {static void Main (string [] args) {using (ServiceHost host = new ServiceHost (typeof (OutputSomething) {host. opened + = delegate {Console. writeLine (host. description. endpoints [0]. address. uri + "started. Press any key to terminate the service! ") ;}; Host. Open (); Console. Read ();}}}}
L client program
Program. cs
Using HighlyConcurrentClient. highlyConcurrentService; using System. net; namespace HighlyConcurrentClient {class Program {static void Main (string [] args) {string AddressIP = string. empty; foreach (IPAddress _ IPAddress in Dns. getHostEntry (Dns. getHostName ()). addressList) {if (_ IPAddress. addressFamily. toString () = "InterNetwork") {AddressIP = _ IPAddress. toString () ;}} Console. writeLine ("local IP:" + AddressIP); using (OutputSomethingClient proxy = new OutputSomethingClient () {for (int I = 0; I <20; I ++) {Console. writeLine (proxy. getContentData (I) ;}} Console. read ();}}}
After the client adds a service reference, the Address may be the IP address of a PC (for example, Address = "http: // 10.92.202.56: 5600/OutputSomething"). This is the address that needs to be changed to the following Nginx Address:
Address = "http://zhyongfeng.com/OutputSomething", configured as follows:
<?xml version="1.0" encoding="utf-8" ?><configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IOutputSomething" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://zhyongfeng.com/OutputSomething" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IOutputSomething" contract="HighlyConcurrentService.IOutputSomething" name="BasicHttpBinding_IOutputSomething" /> </client> </system.serviceModel></configuration>
That is:
5. URL reserved items
In the default Operating System Configuration, Windows Communication Foundation (WCF) creates a globally accessible reserved entry for port 80 so that all users can run the application, in this application, two-way HTTP binding is used for duplex communication.
Returned:
An unprocessed exception of the "System. ServiceModel. AddressAccessDeniedException" type occurs in System. ServiceModel. dll. Other information occurs: HTTP cannot register URL http: // +: 5600/OutputSomething /. The process does not have access to this namespace (for more information, see http://go.microsoft.com/fwlink? LinkId = 70353 ).
Run C: \ windows \ System32 \ cmd.exe as an administrator:
Netsh http add urlacl url = http: // +: 5600/user = "\ Everyone" netsh http add iplisten ipaddress = 0.0.0.0: 5600 firewall inbound rules: netsh advfirewall firewall add rule name = "5600 port" dir = in action = allow protocol = TCP localport = 5600url reserved item delete netsh http delete urlacl url = http: // +: 5600/netsh http show urlacl
You can add a URL reservation as follows:
netsh http add urlacl url=http://+:5600/ user="\Everyone"
6. Deploy the WCF Service Program to three PCs in the LAN
To remotely deploy a WCF Service program, you need to relocate its config configuration file, and change the default IP address 127.0.0.1: 5600 to the IP address of the remote computer:
10.92.202.56: 5600, 10.92.202.57: 5700, 10.92.202.58: 5800
Then start the remote computer's WCF Service Program. The running effect is as follows:
The Running Effect of accessing the WCF server on IE on the local machine:
7. Configure and build an Nginx Cluster
Access the Server Load balancer cluster through the self-built domain name zhyongfeng.com: 80, access C: \ Windows \ System32 \ drivers \ etc \ hosts, and add the following "Custom Domain Name of the local IP Address ":
10.93.85.66 zhyongfeng.com
Configure multiple PCs deployed in WCF (set proxy_connect_timeout to 10 s. If one machine is down, it can be forwarded to another machine) as follows:
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream zhyongfeng.com { server 10.92.202.56:5600; server 10.92.202.57:5700; server 10.92.202.58:5800; } server { listen 80; server_name zhyongfeng.com; location / { proxy_pass http://zhyongfeng.com; proxy_connect_timeout 10s; } }}
Run CMD:
D:\DTLDownLoads\nginx-1.10.2>start nginxD:\DTLDownLoads\nginx-1.10.2>nginx -s reload
Access the WCF server: http://zhyongfeng.com/outputsomething/metadataand run the result:
8. Start the WCF client program
Start the WCF client program and run the following code:
Disable one of the following PCs for Remote Desktop: 10.92.202.56: 5600:
Restart the WCF client. Because the Nginx configuration file sets proxy_connect_timeout to 10 s, the disabled PC 10.92.202.56: 5600 forwards its messages to 10.92.202.57: 5700 after 10 s, continue to be executed by the other two PCs:
9 Summary
WCF is a series of application frameworks developed by Microsoft to support data communication. Through the combination of the open-source framework Nginx, it can provide more scalability. Nginx, in combination with WCF, has a great deal to do with the layout of the LAN. through the integration of the Report Server, email server, and document server in WCF, WCF originally integrated the original windows communication. net Remoting, WebService, Socket mechanism, Nginx makes the Distributed Function of WCF more powerful.
Source code download:
Http://download.csdn.net/download/ruby_matlab/10122670
PDF download:
Nginxcluster-based wcfdistributed Local Network Application