CN107734053A - It is a kind of to support WbApi while realize push and cross-domain solution method - Google Patents

It is a kind of to support WbApi while realize push and cross-domain solution method Download PDF

Info

Publication number
CN107734053A
CN107734053A CN201711070424.5A CN201711070424A CN107734053A CN 107734053 A CN107734053 A CN 107734053A CN 201711070424 A CN201711070424 A CN 201711070424A CN 107734053 A CN107734053 A CN 107734053A
Authority
CN
China
Prior art keywords
cross
domain
server
client
signalr
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201711070424.5A
Other languages
Chinese (zh)
Inventor
秦娜
陈永
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong Inspur Genersoft Information Technology Co Ltd
Original Assignee
Shandong Inspur Genersoft Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong Inspur Genersoft Information Technology Co Ltd filed Critical Shandong Inspur Genersoft Information Technology Co Ltd
Priority to CN201711070424.5A priority Critical patent/CN107734053A/en
Publication of CN107734053A publication Critical patent/CN107734053A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • G06F9/548Object oriented; Remote method invocation [RMI]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/2866Architectures; Arrangements
    • H04L67/30Profiles
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/541Client-server

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The present invention provide it is a kind of supports WbApi while realizes push and cross-domain solution method, belong to field of computer technology, the present invention realizes the client access such as interface support Android, iOS and Web ends by a kind of method, and can be to the cross-domain PUSH message in Web ends.Being primarily adapted for use in needs to support various ways calling, the WebApi of interacting message, realizes that same area lower interface does not access.Realize cross-domain push of the service end to client.Solves WebApi and SignalR cross-domain conflict.

Description

It is a kind of to support WbApi while realize push and cross-domain solution method
Technical field
The present invention relates to computer technology, more particularly to a kind of support WbApi while realize push and cross-domain solution party Method.
Background technology
At present, many software companys using free third party's instrument SignalR to realize that message pushes, in same item On mesh, SignalR configures according to online the step of providing, basic it is achieved that message push or chatroom.According to present The demand of product, most of projects all introduce interface this concept.Interface can provide all data in different clients Obtain and handle, message is also naturally pushed this function and has also given interface.
General WebApi can add cross-domain support when Cross-domain problem is handled inside web.config, and this is very Rough adds cross-domain support, when along with push, the problem of can not being pushed to client just occurs, when cross-domain If deletion, message push can be carried out, but client can not access interface.
The content of the invention
In order to solve the above technical problems, the present invention proposes and a kind of supports WbApi while realize to push and cross-domain solution Certainly method.The cross-domain of WebApi and push are realized that meeting the WebApi of lowest version or highest version can realize that message pushes away simultaneously Send.
In order to realize that interface realizes cross-domain push, used technical scheme is:
It is a kind of to support WbApi while realize push and cross-domain solution method, mainly including herein below:
1. pushing module
WebApi introduces third party's kit " SignalR ".Hub server-side codes are realized, Hub supports to ask to initiation Person (Caller), all clients (Clients), specific group (Group) PUSH message.
2. connection is established at client and server end
After server end realizes Hub server-side codes, the method being connected with SignalR, client have been provided clients with End is actively established and connected with server end, and server can active push message is to customer terminal webpage after establishing connection, so Client need not just resend request or obtain message using polling technique.
3. Cross-domain problem
Introduce SignalR after, WebApi need delete web.config in cross-domain configuration, rewrite HTTP handler- DelegatingHandler, the processing of http response message is delegated to customized processing routine.Solve cross-domain conflict to ask Topic.
Concrete operations are:
1) third-party bag is installed first
2) Hub SignalR connection classes are inherited in addition
It should should include inside class:
2.1) connect:Client connection server, server are (objective by specified key (now using client user Id) and value The ConnectionID at family end) it is added in dictionary, use during push.The present invention is using the cookie guarantors for calling client Key-value pair is saved as, so the function of being also required to web server end is supported.
2.2) disconnect:Disconnect, remove its key-value pair.
2.3) pushed information:Real time information is pushed to online user according to the peculiar information of recipient and push content.
3) addition starts class
SignalR has the cross-domain of oneself:In .net framework 4.5 and .net framework 4.0 some It is different
SignalR has a cross-domain component Microsoft.Owin.Cors of oneself in .net framework 4.5, Added in setting is started;
SignalR adds that " browser can be with cross-domain request in .net framework 4.0 under App_start files The configuration of SignalR end points ";
4) method for calling PUSH message in connection class in the controller;
5) final step, it is exactly cross-domain
When realizing cross-domain, what is used configures API in web.config;
A configuration file is added under App_start files, works as client $ .ajax cross-domain requests for handling Intercepted in the duct during data and change Request.
After cross-domain file is finished writing, configuration is added in global files:
Web terminal processing mode:
1.js is quoted
The push of the reception server is wanted as client, first has to quote the SingalR of signalR.js and server end The siganlr/hub bridge joints automatically generated
2. obtaining example, connection is established
3. be next exactly our call back function, when client has configured, just client and server is sent out respectively Cloth is to testing on IIS.
The beneficial effects of the invention are as follows
1. the cross-domain mechanism of interface will not influence each other:No matter the WebApi of lowest version or highest version can support it is cross-domain, And it need not be configured in web.config, in order to avoid influence the realization of other functions.
Called 2. client is convenient:Web terminal can normal call interface, plus partial code can with server end establish connect Connect.
3. client has the initiative:Client can establish connection or solution according to the business demand of oneself and server end Except connection.
4. reduce performance losses:Third-party instrument itself is have invoked, so the advantage of third party's instrument is inherited, SignalR is integrated with several common transmission means in itself:long pollong、WebSocket、ServerSendEvent、 Forever Frame.Client no pressure is allowed to realize that real-time messages push, client need not just resend request or using wheel Inquiry technology obtains message.
5. interface realizes push function, it is not necessary to realizes that chatroom or message push away by buying the service of push platform Send.
Embodiment
More detailed elaboration is carried out to present disclosure below:
A kind of similar microblogging can carry out personal letter and the product with Android, iOS and web terminal, realize personal letter function, Three kinds of client calls, one interface.It is implementation method below:
Server-side processes mode:
1. since have selected third-party instrument, third-party bag is installed first
Using Install-Package Microsoft.AspNet.SignalR, signalR bags are installed
2. Hub SignalR connection classes are inherited in addition
It should should include inside class:
2.1 connection:Client connection server, server are (objective by specified key (now using client user Id) and value The ConnectionID at family end) it is added in dictionary, use during push.This example is using the cookie for calling client Key-value pair is saved as, so the function of being also required to web server end is supported.
2.2 disconnect:Disconnect, remove its key-value pair
2.3 pushed information:According to the peculiar information of recipient (peculiar information is consistent during with connection server, current client Id) With push content real time information is pushed to online user.
Note:In this connection class, " Context.QueryString [" name "] " this side can not be used by establishing connection Formula, due to client and interface and same project is not belonging to, so interface does not receive Context.QueryString Data.The present embodiment using cookie mode, if other solutions are also possible.
3. addition starts class
SignalR has the cross-domain of oneself:In .net framework 4.5 and .net framework 4.0 some It is different
There is a cross-domain component Microsoft.Owin.Cors of oneself in .net framework 4.5, starting Added in setting:
Add that " browser can be with cross-domain request SignalR under App_start files in .net framework 4.0 The configuration of end points ":
4. the method for PUSH message in connection class can be called in the controller
ChatWithTracking.PushMsg(fan.CustomerID.ToString(),tipText);
5. final step, it is exactly cross-domain
When realizing cross-domain, what is used configures API in web.config, does not just have to compiling.
<Add name=" Access-Control-Allow-Origin " value=" * "/>
<Add name=" Access-Control-Allow-Methods " value=" GET, POST, PUT, DELETE, OPTIONS"/>
<Add name=" Access-Control-Allow-Headers " value=" Content-Type, Authorization,Accept,X-Requested-With"/>
<Add name=" Access-Control-Allow-Credentials " value=" true "/>
This is the very rough cross-domain support that adds, but signalR it is cross-domain be individually walk it is a kind of cross-domain, and it Preceding rough configuration file conflict, just need this when oneself inside code to judge, one is walked when request is signalR Kind cross-domain configuration, other when walk another kind.
A configuration file is added under App_start files, works as client $ .ajax cross-domain requests for handling Intercepted in the duct during data and change Request.
After cross-domain file is finished writing, configuration is added in global files:
GlobalConfiguration.Configuration.MessageHandlers.Add(new CoreHandler ());
Till now, the push of server has just configured.
Web terminal processing mode:
1.js is quoted
The push of the reception server is wanted as client, first has to quote the SingalR of signalR.js and server end The siganlr/hub bridge joints automatically generated
@Scripts.Render ("~/Scripts/jquery.signalR-1.2.2.min.js ")
@Scripts.Render("http://www.api.com/signalr/hubs")
2. obtaining example, connection is established.Here is that web client establishes the code portions for being connected and disconnected from being connected with server Point.
3. next it is exactly our call back function
When client has also configured, it is possible to client and server is published on IIS tested respectively.

Claims (3)

1. a kind of support WbApi while realize push and cross-domain solution method, it is characterised in that
Mainly include herein below:
1) WebApi introduces third party's kit " SignalR ";Hub server-side codes are realized, Hub supports to ask to initiation Person, all clients, specific group PUSH message;
2) connection is established at client and server end
After server end realizes Hub server-side codes, the method being connected with SignalR, client master have been provided clients with Dynamic established with server end connects, and establishes after connection server active push message to customer terminal webpage;
3) Cross-domain problem
After introducing SignalR, the cross-domain configuration in WebApi deletions web.config, rewriting HTTP handler- DelegatingHandler, the processing of http response message is delegated to customized processing routine, solves cross-domain conflict and ask Topic.
2. according to the method for claim 1, it is characterised in that
Concrete operations are:
1) third-party bag is installed first
2) Hub SignalR connection classes are inherited in addition
It should should include inside class:
2.1) connect:Specified key and value are added in dictionary by client connection server, server, use during push;
2.2) disconnect:Disconnect, remove its key-value pair;
2.3) pushed information:Real time information is pushed to online user according to the peculiar information of recipient and push content;
3) addition starts class
SignalR has a cross-domain component Microsoft.Owin.Cors of oneself in .net framework 4.5, is opening Added in dynamic setting;
SignalR adds that " browser can be with cross-domain request in .net framework 4.0 under App_start files The configuration of SignalR end points ";
4) method for calling PUSH message in connection class in the controller;
5) final step, it is exactly cross-domain
When realizing cross-domain, what is used configures API in web.config;
A configuration file is added under App_start files, works as client $ .ajax cross-domain request data for handling When intercept in the duct and change Request;
After cross-domain file is finished writing, configuration is added in global files, the push of server just configures completion.
3. according to the method for claim 2, it is characterised in that
Web terminal processing mode:
1) .js is quoted
The push of the reception server is wanted as client, first has to quote signalR.js and the SingalR of server end is automatic The siganlr/hub bridge joints of generation;
2) obtains example, establishes connection;
3) next. is exactly call back function, and when client has configured, just client and server is published on IIS respectively Test.
CN201711070424.5A 2017-11-03 2017-11-03 It is a kind of to support WbApi while realize push and cross-domain solution method Pending CN107734053A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711070424.5A CN107734053A (en) 2017-11-03 2017-11-03 It is a kind of to support WbApi while realize push and cross-domain solution method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711070424.5A CN107734053A (en) 2017-11-03 2017-11-03 It is a kind of to support WbApi while realize push and cross-domain solution method

Publications (1)

Publication Number Publication Date
CN107734053A true CN107734053A (en) 2018-02-23

Family

ID=61222519

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711070424.5A Pending CN107734053A (en) 2017-11-03 2017-11-03 It is a kind of to support WbApi while realize push and cross-domain solution method

Country Status (1)

Country Link
CN (1) CN107734053A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109688280A (en) * 2018-08-21 2019-04-26 平安科技(深圳)有限公司 Request processing method, request processing equipment, browser and storage medium
CN112581010A (en) * 2020-12-25 2021-03-30 政和科技股份有限公司 System and method for supply and demand butt joint matching of industrial products

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2852982A1 (en) * 2011-10-28 2013-05-02 Lxm Pty Ltd Data interchange system
CN104580532A (en) * 2015-02-05 2015-04-29 中国农业银行股份有限公司 Cross-platform application system
CN105930450A (en) * 2016-04-21 2016-09-07 裴克铭管理咨询(上海)有限公司 Big data analysis processing tool

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2852982A1 (en) * 2011-10-28 2013-05-02 Lxm Pty Ltd Data interchange system
CN104580532A (en) * 2015-02-05 2015-04-29 中国农业银行股份有限公司 Cross-platform application system
CN105930450A (en) * 2016-04-21 2016-09-07 裴克铭管理咨询(上海)有限公司 Big data analysis processing tool

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
CHEN.S: "SignalR和跨域问题(ASP.NET MVC)", 《博客园》 *
ITPUBLISHER: "asp.net mvc 4 - Signalr Hubs Not found (403)", 《ITKEYWORD》 *
李燕: "基于ASP.NET SignalR 的实时Web 功能的实现", 《电脑知识与技术》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109688280A (en) * 2018-08-21 2019-04-26 平安科技(深圳)有限公司 Request processing method, request processing equipment, browser and storage medium
CN109688280B (en) * 2018-08-21 2021-06-04 平安科技(深圳)有限公司 Request processing method, request processing device, browser and storage medium
CN112581010A (en) * 2020-12-25 2021-03-30 政和科技股份有限公司 System and method for supply and demand butt joint matching of industrial products

Similar Documents

Publication Publication Date Title
US9009599B2 (en) Technique for handling URLs for different mobile devices that use different user interface platforms
KR102527445B1 (en) Messaging bot technology for rich communication
CN106357699B (en) Network system, service platform login method and system
CN107343027B (en) APP sharing method
TWI685228B (en) Information transmission method and device
US20160234383A1 (en) Calling an Unready Terminal
JP5006328B2 (en) Method and system for calling MIDlet from a web browser on a local device
CN103618606A (en) App login method verified through short message
CN109104701B (en) Information sending method based on equipment identification code and server
KR102066802B1 (en) Business processing method and device
WO2017016174A1 (en) Strange number marking method and device
CN108549586B (en) Information processing method and device
CN108696899A (en) Sip message transmits and method of reseptance and transmission and reception device
CN103179021A (en) Method and system for aggregating heterogenous micro-blogs
CN105704001A (en) WeChat server message distribution method and WeChat server message distribution system
CN103167014A (en) Method and device of sharing resources with browsers
CN107734053A (en) It is a kind of to support WbApi while realize push and cross-domain solution method
CN102594859B (en) A kind of rendering method of business datum, terminal, server and system
CN106789832B (en) Data processing method, device and system in call process
CN105049210B (en) A kind of general account register method and device
CN108076110B (en) Electronic data exchange system and apparatus comprising an electronic data exchange system
CN110442416B (en) Method, electronic device and computer-readable medium for presenting information
CN103634348A (en) Terminal device and method for releasing information
CN113760487B (en) Service processing method and device
CN110830662B (en) Outbound telephone data generation method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20180223