WCF服务连接 [英] WCF Service connection
问题描述
大家好
我创建了WCF服务,并通过UWP应用程序使用了它.我遇到一个问题,即有时客户端连接会在服务器完成返回之前就断开,从而导致数据不同步.如果客户端没有,我需要服务器回滚 完全接收返回对象.
I have created a WCF service and consumed it with a UWP app. I have an issue where at times the clients connection drops just before the server completes its return causing the data to get out of sync. I need to server to roll back if the client does not fully receive the return object.
我刚刚发现UWP现在支持System.Transaction,因此我无法将服务包装在事务范围中
I have just discovered that UWP does now support System.Transaction so I cannot wrap my service in transaction scope
我正在努力工作,但是受到阻碍,进度停滞了.
I am working on a work around but have be hindered and progress has stalled.
我的问题是:
1.客户端是否可以为每个调用(同一会话)使用相同的WCF服务器端对象?我注意到,每次对该服务的调用都会触发WCF构造函数.
1. is there a way for the Client to use the same WCF server side object for every call (same session)? I have noticed that every call to the service fires the WCF constructor.
和
2.当客户端将数据发送到服务并等待响应时,是否可以在服务器端测试客户端是否成功接收了响应.
2. when the client sends data to the service and is waiting for a response, is there a way to test on the server side that the client received the response successfully.
示例
公共字符串getname(){
public string getname(){
返回"Melinda"; <--当客户收到成功事件或失败事件时是否发生此类事件,或者失败
return "Melinda"; <---is there a success event or such when the client receives this, or a failure
}
谢谢
推荐答案
>>客户端是否可以为每个客户端使用相同的WCF服务器端对象通话(同一会话)?
>>is there a way for the Client to use the same WCF server side object for every call (same session)?
您可以尝试InstanceContextMode = InstanceContextMode.PerSession.但是WCF构造函数将被每次调用都调用.
You could try InstanceContextMode =InstanceContextMode.PerSession. But the WCF constructor will be called by every called.
您可以在下面的链接中获取有关InstanceContextMode = InstanceContextMode.PerSession的更多信息.
You could refer below link for more information about InstanceContextMode =InstanceContextMode.PerSession.
#会话,实例化和并发性
#Sessions, Instancing, and Concurrency
https://msdn.microsoft.com/en-us/library/ms731193(v = vs.110).aspx
>>当客户端将数据发送到服务并正在等待响应时,有没有一种方法可以在服务器端测试客户端是否成功接收了响应
>>when the client sends data to the service and is waiting for a response, is there a way to test on the server side that the client received the response successfully
对于此问题,我认为您可以尝试双工,也可以尝试以下链接.
For this issue, I think you could try duplex, and you could try below link.
#如何在UWP应用中的WCF中使用双工和TCP绑定
#How to use duplex and TCP binding in WCF in UWP app
https://code.msdn.microsoft.com/windowsapps /如何使用双工和TCP-9b14b1bd
此外,如果您对第二个问题有任何疑问,我建议您发布一个新主题,然后我们可以将重点放在一个主题中.
In addition, if you have any issue for the second question, I would suggest you post a new thread, and then we could focus on the specific issue in one thread.
这篇关于WCF服务连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!