I'm working on a protocol which is designed to be implemented with SOAP over HTTP.
WSDL files are provided by a third party.
I used wsdl.exe to generated a proxy class and created a Web Service Project in VS.
wsdl.exe yourFile.wsdl /l:CS
I got a cs from a unwrapping wsdl.
Snippet:
[System.Web.Services.Protocols.SoapHeaderAttribute("chargeBoxIdentity")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("/ClearCache", RequestElementName="clearCacheRequest", RequestNamespace="urn://Ocpp/Cp/2012/02/", ResponseElementName="clearCacheResponse", ResponseNamespace="urn://Ocpp/Cp/2012/02/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("status")]
public abstract ClearCacheStatus ClearCache();
Implementation 1 (Server Side)
A central system (Server) connected to devices. When a device initialized, it sends an authorisation to central system.
And Server response an authorisation message back.
I have already done with Server Side which provides all clients send requests to Server. And Server response the messages.It works well.
Implementation 2 (Central system send a message to a device)
The other part of implementation is a central system need to send message to device (ex. clear devices cache, please see a snippet above). I add those methods to web service as well.
My questions are...
How can I send a message to devices through a proxy from Web Service?
It's impossible to call a method from Web Service sending requests to device? Any suggestions?
Or I need to create a project implementing a ClearCache method and format as a SOAP message to trigger?
Thanks!
I dont think it is a good idea to allow the Central system to directly communicate with the clients (Will create a huge noise in the network if the number of devices is high and the server tries to send several messages)..
A better approach will be to allow all the messages that the server intends to send to the client to be cached locally in the server machine. The clients should periodically communicate with the server using another web service and obtain the cached information that you intend to send to the clients.
you can design a method that sends the guid of the client as a parameter in the web service call.
On the server you maintain a database and keep track of the messages that needs to be sent to the clients.
use a timer object in the clients. On elapse of the timer define a method that communicates with the server by sending its guid. On the server side use this guid as a Primary Key to identify wat messages need to be sent to the client and then reply that while returning from the message.
The client then uses this return value to decide how to respond.
Related
Is it possible to send message from one client to another client that is connected to the same server?
I want send data from one client to server Then send to specific client. I think I need to get client ID but I dont know how to get this id and how to send this message to that client from server.
I have a sample here. This is a chat server-client application. Multiple clients can connect to the server. When a client writes a message, the server simply broadcasts it for all clients who are receiving server stream RPC.
https://github.com/cactuaroid/GrpcWpfSample
See these server side implementation. When a client calls Subscribe(), it awaits m_chatService.Added event. When a client calls Write(), it raises the event and event args ChatLog is written on responseStream.
https://github.com/cactuaroid/GrpcWpfSample/blob/f6e8c4b2493c23cdcbaffeca29b5bb6705fbe95c/GrpcWpfSample.Server/Grpc/ChatServiceGrpcServer.cs
https://github.com/cactuaroid/GrpcWpfSample/blob/f6e8c4b2493c23cdcbaffeca29b5bb6705fbe95c/GrpcWpfSample.Server/Model/ChatService.cs
You can add your logic such as specifying channel name to subscribe/write, or define OpenChannel(string password) to be called by client at the first time so that server can bind the client IP address to the channel, whatever as you like.
There's no special gRPC feature that would allow you to do this (all RPC are between a server and a client, there's no "broadcast" or "selective broadcast" feature to reach out to other clients connected to the same server.
The logic you want is something that can definitely be implemented and but details of such solution depend on your need. A naive approach that might work is e.g. this:
each client opens a bidi-streaming call to the server
server keeps a directory of connected clients
once server receives a message from a client, it selects which client it should forward to based on the directory.
server forwards the message to a client.
Needless to say this setup feels a bit complicated (you're basically implementing your own network protocol on top of gRPC), so even though it might be just the right thing for you to do, it would make sense to think about how to simplify the protocol so that you can use features directly supported by gRPC.
Here’s our architecture:
JIRA webhook sends messages to a Java Jersey REST service when issues are assigned.
C# client application registers the username/host machine combo with the Java web service when a user logs into the machine
When the web service receives a message from JIRA, it finds the assignee username and sends the required data to the C# client app on the host machine(s) the user is logged into.
I’ve thought of a couple approaches to solve the web service to client message.
My first is opening a TCP port on the client and having the service send each message directly to it. This is the most straight-forward approach but makes the client a little heavy in that it maintains the list of user assigned ticket data that they can then manipulate (acknowledge or remove).
The other is having the service maintain the data model and the client requests data periodically. This makes the client simpler but then I’d have to implement a polling interval to grab data, and add some POST methods for acknowledging and removing data from the user’s list.
I was looking into different ways to have the client register a channel with the service, like ServiceStackEvents, but I can’t see a way to make that work with a C# client and Java service. Something like that would be perfect. A way for the service to send callbacks or event messages to a client based on a user filter.
If someone has some suggestions or knows of an API to help with this, please post a link so I can dig into it. The POSTs are all working swimmingly, it’s just getting the data back to the clients that I’m struggling with the best approach.
Thanks!
Client polling is not a terrible solution.
But if you want a firewall and proxy friendly duplex protocol, check out WebSockets https://en.m.wikipedia.org/wiki/WebSocket.
I would like to implement some instant messenger-like application for Windows Phone 8.1, and I have a WCF REST service which connects to a MySQL database (I know, SQL Server would be better, but renting a server for MySQL is cheaper... :D), which stores users, etc.
I know that REST is stateless, but I would like to implement something session-like methodology to make my web service able to deliver incoming messages through the service to the recipients immediately (sending messages/request to the web service is not a problem).
So my question is, what technology / solution would you recommend for me to do this?
My basic concept is:
user registers from WP - service saves data to db
user logs in from WP - I will need some session like data, to let the server know where should it deliver messages (for example user's guid, ip address or something else, something that signals that the user is still online though the application is suspended and runs in background, and still able to receive messages)
user sends a message from WP to the rest service which should contain data about the sender (at least the user's guid, but don't wanna store too much data about user on the client side), the recipient, the content, timestamp, etc) via sending a http request for example using an uri template like this: message/send and in the request body there is the recipient's id, content, etc
user adds a contact
WCF service receives the request, processes it, sends to the recipient by identifying via it's guid and there comes the problem, should know something about the device, an ip address or session or something like that
recipient receives the message.
I hope I could describe my problem properly, and there will be anyone who can help me ^^
I would appreciate any helps!
Thanks in advance!
There’re several approaches that will work.
Use Microsoft’s push notification service (MPNS). Here’s an overview. This is the most power-efficient way, and your users will even be able to receive messages while your app’s not running.
Use Microsoft’s Windows Notification Service (WNS). It's only supported on WP 8.1, but the latency is much better (AFAIR they promise delivery time within 5 seconds).
Or, you can use some bi-directional protocol. Choose between:
WCF server + net-tcp transport: on client you'll have to implement binding + framing + SOAP yourself, the higher levels of the protocol (binary XML serialization) is in the framework.
Google protocol buffers over TCP
WebSockets: MS has the support in 8.1 SDK, third party is available for WP Silverlight
SignalR: 3rd party implementation is available
I have a server which is connected to a few clients (with WCF and netTcpBinding).
At an undefinite point in time I want the server to call the method of a specific client (and have a string as a parameter). The server only knows which client when he wants to call it.
Basically one client has to wait for a server to send him a message (but in the meantime, other clients call the server as well) and the server needs to know exactly which client he needs to call. (The client has an attribute and the server wants to call the method on the client with a specific attribute)
Is there a way to do this?
EDIT: I thought of a possibility, but I think there is a better way.. for the moment the client will call a method with parameters specifying the ip and port of the client. The server will add it to a list and when the server wants to call the client, he searches the list for the attribute and connects to the client (on the client a service is hosted as long as the client is waiting)
WCF already has support for this built in. You need to create a duplex contract. The server can then call any connected clients whenever it wants.
I am creating a WCF service where multiple users connect to it. On my WCF I implement callback contracts so that if a user makes a specific action it can notify other computers that are connected to the same WCF service. So if Company A creates an action on the WCF service then the WCF service will make a callback to all Company A machines that are connected to it. Company B will receive no notifications for example.
Anyways so far everything works great NOW. what about in the future where there are more connections at the same time? will that cause a problem?
To avoid that problem will it be better to create a web service where connections are not held open? The problem with this approach is the callback mechanism where the web service needs to send a notification to multiple computers In order to resolve the callback problem I am going to have all machines sending a UDP packet every 10 seconds to the web server. (this will make the router open a port so that the web server can reply in case it needs to) If the web service needs to send a notification to all computers on Company A for instance then it will Send multiple UDP packets. If a computer receives a UDP packet from the web service then it knows it has to make a request to perform the callback. Should I use this approach?