Tag: #wcf

WCF在自托管服务上流式传输大数据(500MB / 1GB)

我目前遇到一个问题,试图使用WCF自托管服务(没有IIS)发送大数据。 使用流式传输结果传输500MB,我的服务因System.OutOfMemoryException而崩溃。 是否有可能传输这么多数据? 这是我的WCF配置: 我的客户端配置:

WCF,HTTPS与HTTP

有两个样本 对于HTTP : using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Security; namespace ConsoleApplication1 { internal class Program { private static void Main(string[] args) { string addressHttps = String.Format(“http://{0}:51222”, Dns.GetHostEntry(“”).HostName); var wsHttpBinding = new BasicHttpBinding(); var serviceHost = new ServiceHost(typeof (HelloWorldService), new Uri(addressHttps)); Type endpoint = typeof (IHelloWorldService); serviceHost.AddServiceEndpoint(endpoint, wsHttpBinding, […]

异步使用同步WCF服务

我目前正在将客户端应用程序迁移到.NET 4.5以使用async / await。 该应用程序是WCF服务的客户端,该服务目前仅提供同步服务。 我现在想知道, 我应该如何异步使用这种同步服务 ? 我正在使用渠道工厂连接到WCF服务,利用服务器和客户端共享的服务合同。 因此,我无法使用VisualStudio或svcutil的自动生成来生成异步客户端代理。 我已经阅读了这个相关的问题 , 该问题是关于是否使用Task.Run在客户端包装同步调用,或者是否使用异步方法扩展服务契约。 答案表明,服务器提供的“真正的”异步方法对于客户端性能更好,因为没有线程必须主动等待服务调用完成。 这对我来说很有意义,这意味着同步调用应该包含在服务器端。 另一方面,Stephen Toub在这篇博文中总体上拒绝这样做。 现在,他没有在那里提到WCF,所以我不确定这是否只适用于在同一台机器上运行的库,或者它是否也适用于远程运行的东西,但是异步性的引入对其有实际影响。连接/传输。 毕竟,由于服务器实际上并不是异步工作(并且可能不会在另一个时间内工作),因此某些线程将始终必须等待:在客户端或服务器上。 这同样适用于同步使用服务(当前,客户端在后台线程上等待以保持UI响应)。 例 为了使问题更清楚,我准备了一个例子。 完整项目可在此处下载 。 服务器提供同步服务GetTest 。 这是当前存在的,并且工作同步发生的地方。 一种选择是将其包装在异步方法中,例如使用Task.Run ,并将该方法作为合同中的附加服务提供(需要扩展合同接口)。 // currently available, synchronous service public string GetTest() { Thread.Sleep(2000); return “foo”; } // possible asynchronous wrapper around existing service public Task GetTestAsync() { return Task.Run(() […]

WCF错误 – 没有端点正在侦听

我正在开发一个WCF服务,在Window server 2003上运行IIS6。我已经构建了一个测试客户端来与WCF服务进行通信,我收到以下错误。 我已经看了几天这个错误,并在论坛上通过了人们的建议,但没有运气。 任何帮助将不胜感激,非常感谢 在https://webbooking.infodata.uk.com/Synxis/Synxis.svc上没有可以接受该消息的端点。 这通常是由不正确的地址或SOAP操作引起的。 有关更多详细信息,请参阅InnerException(如果存在)。 System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, […]

对WCF服务的异步调用不会保留CurrentCulture

根据这个问题的答案async/await call应该保留CurrentCulture。 就我而言,当我调用自己的异步方法时,将保留CurrentCulture。 但是,如果我调用某种WCF服务方法,则不会保留CurrentCulture,而是将其更改为看起来像服务器默认线程文化的东西。 我查看了调用托管线程的内容。 它发生在每个代码行都在一个托管线程上执行(ManagedThreadId保持不变)。 在调用我自己的异步方法后,CultureInfo保持不变。 但是当我调用WCF的方法时,ManagedTrheadId保持不变,但CurrentCulture已更改。 简化的代码如下所示:: private async Task Test() { // Befoe this code Thread.CurrentThread.CurrentCulture is “ru-RU”, ie the default server’s culture // Here we change current thread’s culture to some desired culture, eg hu-HU Thread.CurrentThread.CurrentCulture = new CultureInfo(“hu-HU”); var intres = await GetIntAsync(); // after with await Thread.CurrentThread.CurrentCulture is still […]

调用基于异步任务的WCF方法是否利用I / O完成端口或线程池线程来调用延续?

我有以下WCF合同: [ServiceContract(Namespace = “http://abc/Services/AdminService”)] public interface IAdminService { [OperationContract] string GetServiceVersion(); // More methods here } GetServiceVersion是一个返回一些字符串的简单方法。 它用作ping来检查服务是否可访问。 现在我想异步调用它,认为它比使用.NET线程在后台调用它更有效。 所以,我为此提出了以下接口: [ServiceContract(Namespace = “http://abc/Services/AdminService”)] public interface IMiniAdminService { [OperationContract(Action = “http://abc/Services/AdminService/IAdminService/GetServiceVersion”, ReplyAction = “http://abc/Services/AdminService/IAdminService/GetServiceVersionResponse”)] Task GetServiceVersionAsync(); } 这使得可以异步调用GetServiceVersion API: var tmp = new ChannelFactory(“AdminServiceClientEndpoint”); var channelFactory = new ChannelFactory(tmp.Endpoint.Binding, tmp.Endpoint.Address); var miniAdminService = channelFactory.CreateChannel(); return miniAdminService.GetServiceVersionAsync().ContinueWith(t […]

WCF服务方法参数,bool指定

可能重复: WCF不会返回int 尝试使用我自己的WCF服务,如下所示: [ServiceContract] public interface IReturnService { [OperationContract] bool GetTransactionList(int lRetailStoreID, int lWorkstationNmbr, int lTaNmbr); } 但是当我从客户端调用服务时,我得到的错误是没有方法GetTransactionList有3个参数,而是我得到这个头: myWCF.GetTransactionList(int lRetailStoreID, bool lRetailStoreIDSpecified, int lWorkstationNmbr, bool lWorkstationNmbrSpecified, int lTaNmbr, bool lTaNmbrSpecified, out bool GetTransactionListResult, out bool GetTransactionListResultSpecified) 任何人都知道为什么会发生这种情况以及如何解决它? 如果需要更多信息,请与我们联系。

WCF不会返回int

我正在C#中构建一个WCF,并且客户端同时使用它。 由于某种原因,我无法获得返回int的方法。 这是我的合同: [ServiceContract] public interface IMData { [OperationContract] int ReturnAnInt(); [OperationContract] String HelloWorld(); } 这是我实现它的地方: public class MData : IMData { public String HelloWorld() { return “Hello World”; } public int ReturnAnInt() { return 5; } } 我正在使用Visual Studio,而对于客户端,我将此WCF导入为Web引用。 现在由于某种原因,当我声明一个MData实例并尝试调用HelloWorld时,没有问题,但是在调用ReturnAnInt时出现编译错误。 MData m = new MData(); String helloWorld = m.HelloWorld(); int result = m.ReturnAnInt(); 我使用ReturnAnInt得到的错误是:“方法没有重载’ReturnAnInt’需要0个参数”所以然后我鼠标hover以查看Visual […]

你能通过WCF服务传递Func 吗?

Func是一个可序列化的类,但是当我尝试通过服务将其作为参数传递时。 我被告知它“不是一个已知的类型”。 我试过这里的解决方案无济于事。 非常感谢那里……

更改WCF中的默认日期序列化

有没有改变WCF中DateTime的默认JSON序列化/反序列化? 目前,DateTime序列化为/Date(1372252162657+0200)/格式,应该没问题,但是当我的服务器不是UTC(我无法更改)时,我遇到了问题。 此服务正在处理的所有日期/时间数据均为UTC格式。 当服务器使用UTC时,一切正常。 但是,staging / prod环境设置为GMT + 1(Paris),序列化器假设日期/时间是GMT + 1,完全忽略属性Kind 。 因此,您希望调用DateTime.SetKind()并将其设置为UTC将无法正常工作。 实际上,序列化时间延迟了一个小时。 我可以做双向日期对话(它在反序列化时也做出相同的假设,因此它总是GMT + 1)对话的日期:UTC到/从服务器时间,但这是乏味的。 所以我想也许我可以覆盖默认的序列化行为。