Tag: #wcf

WCF列表序列化/反序列化错误

我有以下ServiceContract和DataContract类: [ServiceContract] public interface IWcfService { [OperationContract] Response GetData(); } [DataContract] public class Response { [DataMember] public Dictionary Data { get; set; } } 当Response.Data字典的值为int,string,double或任何其他“简单”基元类型时,WCF可以成功序列化该对象。 但是当Response.Data字典的值为List 类型时,客户端在接收到数据并尝试反序列化时抛出以下exception: Message=The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:GetDataResult. The InnerException message was ‘Error in line […]

如何在Windows Universal App中使用双工wcf服务

如何在Windows通用应用程序中使用双工合约使用wcf服务? 我正在使用PlatformNotSupportedExcetpion: Operation is not supported on this platform. 尝试在Windows Universal App中使用双面wcf服务时出现运行时exception,目标是Windows 10(10.0; Build 10240) 根据msdn,它支持API。 如果不可能,我应该如何进行我的方案? 我有两个应用程序(控制台和Windows通用xaml应用程序)在同一台机器上运行,我需要双向通信。 我有创建服务主机的clasic .net 4.6控制台应用程序: var host = new ServiceHost(typeof(MyService), new Uri(“net.tcp://localhost:8008/MyService”)); var binding = new NetTcpBinding(); //I’ve also tried net http binding binding.Security.Mode = SecurityMode.None; host.Description.Behaviors.Add(new ServiceMetadataBehavior()); host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), “mex”); host.AddServiceEndpoint(typeof(IMyService), binding, “”); host.Open(); 服务合约: [ServiceContract(CallbackContract = typeof(IMyServiceCallback))] […]

将.NET类库(主要定义CRUD操作)公开为服务

将现有(类)库 (主要定义CRUD操作)作为服务 ( WCF服务或WCF数据服务 )公开的最佳,有效和最快的方法是什么,以便它可以与Silverlight或Ajax一起使用。 是否有工具 (代码生成器,RAD工具)可以支持这个? 在此先感谢您的帮助和提示。

我希望能够使用lambda表达式来指定要通过wcf服务返回的值范围

我不知道这是否可能……但它会很酷。 问题是,是否有可能,但如果可能的话,还有一些例子。 我不确定您将使用什么方法签名来传递lambda表达式。 例如方法IList GetGroups() 你如何修改它以便能够将lambda表达式传递给它? 接下来的问题是如何编写lambda表达式以返回所有Group对象,例如 where .deleted == false或 where .DateAdded > aDate 是的,我想把月亮放在棍子上;)先谢谢你。 (编辑我认为这实际上有点不合理,因为实际上会获取数据的数据访问层……但是假设您正在通过服务查询某些对象集合而不必担心dal )。

强制配置在wcf客户端c#中使用tls 1.0

我们有一个Web应用程序,其客户端使用WCF实现。 此客户端使用SSL_LVL3与外部服务进行握手。 事实certificate该服务刚刚禁用了SSL_LVL3,因此我们需要将其更改为TLS 1.0。 有一种方法可以强制C#中的TLS安全性: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; 但它会改变应用程序使用的所有服务的安全性,而不是所有服务都接受TLS。 我们想要的是更改web.config以强制WCF服务使用TLS。 有没有办法做到这一点? 这是服务的绑定:

在服务器上反序列化WCF消息

我实现了一个自定义消息检查器(通过IDispatchMessageInspector)来拦截在WCF服务的服务器端接收的消息,因此我可以尝试反序列化消息并应用一些特定的业务逻辑。 我遇到的问题是当我将MessageBuffer的内容写入新的MemoryStream然后尝试反序列化时,我收到一条错误,上面写着“根级别的数据无效。第1行,第1行”。 我知道传入的数据是有效的,因为跳过检查器可以使一切正常。 示例代码: public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext) { MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue); request = buffer.CreateMessage(); string msg = buffer.CreateMessage().ToString(); var dc = new DataContractSerializer(typeof(Adder)); using (var stream = new MemoryStream()) { buffer.WriteMessage(stream); stream.Position = 0; //deserializing error occurs here var c = dc.ReadObject(stream); } return null; } 这是Adder类/接口: [DataContract(Name […]

在为WCF服务生成类型时,.NET加载了寻找另一个版本的程序集

尝试在Visual Studio 2013中向ASP.NET Web应用程序添加服务引用时出现此错误。我在项目中引用了Microsoft.Owin.Security版本2.1.0.0。 但是我很沮丧他为什么要寻找2.0.1.0版本? 无法导入wsdl:portType详细信息:运行WSDL导入扩展时抛出exception:System.ServiceModel.Description.DataContractSerializerMessageContractImporter错误:无法加载文件或程序集’Microsoft.Owin.Security,Version = 2.0.1.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35’或其依赖项之一。 该系统找不到指定的文件。

从WCF返回多个响应

我在服务中有一个WCF服务和一个名为GetStudentList()的方法。当它返回单个响应时工作正常。这样的东西 [WebGet(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)] List GetStudentList(); 但我想返回多个响应,即xml和json都是这样的 [WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] [WebGet(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)] List GetStudentList(); 有可能吗?如果是,那怎么样?

由客户端看不到相同类型的Web服务引发的自定义exception(使用共享程序集)

我创建了一个自定义exceptionInvalidSessionException 。 但是,当尝试捕获或评估引发的exception是否属于该类型时,它不起作用。 这意味着EX is和Catch Ex都不会评估为InvalidSessionException try { acc = this.fda.GetAccountHeader(this.selectedTicket.AccountId); } catch (Exception ex) { if (ex is Enterprise.Data.InformationModel.CustomExceptions.InvalidSessionException) { this.lblError.Text = Resources.Resource.error_sessionedTimedOut; this.MPError.Show(); } return; } 我也试过(结果没有任何差别) catch (Enterprise.Data.InformationModel.CustomExceptions.InvalidSessionException ex) { this.lblError.Text = Resources.Resource.error_sessionedTimedOut; this.MPError.Show(); return; } catch (Exception ex) { return; } 据我所知,抛出的exception是正确的类型。 更多信息: ex.GetType().FullName = “System.ServiceModel.FaultException1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]” 服务上是否启用了重用类型?

System.IO.IOException:由于意外的>数据包格式,握手失败了?

有谁知道这意味着什么? System.Net.WebException:基础连接已关闭:发送时发生意外错误。 —> System.IO.IOException:由于意外的数据包格式,握手失败。 System.Net.Security.SslState.Ss上的System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)中的System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest)。 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,Byte [] buffer,AsyncProtocolRequest)上的System.Net.Security.SslState.StartSendBlob(Byte []传入,Int32计数,AsyncProtocolRequest asyncRequest)中的CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest) asyncRequest)System.Net上的System.Net.Se.SlsStream.CallProcessAuthentication(对象状态)中的System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)处于System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup的System.Threading.ExecutionContext.runTryCode(Object userData) (TryCode代码,CleanupCode backoutCode,Object userData)在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionCont) 在System.Net.TlsStream.Write(Byte [])的System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult结果)的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)中的ext,ContextCallback回调,对象状态)在System.Net.ConnectStream.WriteHeaders(布尔异步)处的System.Net.PooledStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)处的缓冲区,Int32偏移量,Int32大小)—内部exception堆栈跟踪的结束 – – 在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan超时)处的System.Net.HttpWebRequest.GetResponse()处 编辑: 这是我打电话的方法: _productsService = new ProductsPortTypeClient(); _productsService.GetResortProducts(GetProductsCredentials(),GetResortProductParams());