Tag: #wcf

反序列化请求消息正文以进行操作时出错

我正在编写一个服务适配器来使用由另一个供应商(Pega)托管的Web服务。 更改此服务不适合我。 当我调用方法时,我收到错误: “反序列化操作请求消息的主体时出错” 我尝试增加maxStringContentLength和所有。 没有任何效果。 在检查响应XML时,我看到几个long和int变量的空值我相信这就是原因。 这有什么问题吗?

WCF DataService(OData)和CORS

我正在尝试使用跨域请求的WCF DataService。 我发现这有关如何使用CORS的WCF服务: http : //blogs.microsoft.co.il/blogs/idof/archive/2011/07/02/cross-origin-resource-sharing-cors-and -wcf.aspx 我下载了示例,但无法使用DataService。 它适用于示例服务,但不适用于我的DataService。 这是我非常简单的WCF DataService: public class TestService : DataService { public static void InitializeService(DataServiceConfiguration config) { config.UseVerboseErrors = true; config.SetEntitySetAccessRule(“Items”, EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } } TestService.svc文件: DataContext也很简单: public class DataContext : DbContext { public DbSet Items { get; set; } } 但是,预检选项请求返回的是501.我是否缺少让CORS与Dataservice一起工作?

IIS下的多个端点

我一直在尝试在IIS下托管的服务中添加新端点,但过去一天左右无法弄清楚。 这是我的理解: 您可以在IIS下拥有多个端点,只要它们具有唯一的地址即可。 您可以分配一个基地址,但它将被IIS中的虚拟目录设置覆盖。 我的虚拟目录是http:// localhost / WcfCert / 我可以使用http://localhost/wcfcert/service1.svc启动服务 但http://localhost/wcfcert/test/service1.svc/test在IE或客户端应用程序中不返回任何内容 我在这里错过了什么? 编辑: 所以我做了进一步的测试,这就是我发现的。 如果我启动WcfTestClient.exe并添加http:// localhost:1523 / Service1.svc或http:// localhost:1523 / Service1.svc / mex ,它将在该地址下添加两个端点。 所以这里是我的问题不应该http:// localhost:1523 / Service1.svc只代表第一个端点? 为什么添加该地址会带来两个端点? 但如果我尝试添加http:// localhost:1523 / Service1.svc / test我得到 错误:无法从http:// localhost:1523 / Service1.svc / test获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。 有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS-Metadata Exchange错误URI: http:// localhost:1523 / Service1.svc / test元数据包含无法解析的引用:’ http:// localhost:1523 / Service1.svc / […]

动态忽略数据成员被序列化

我们有一个使用多个DataContracts的现有WCF服务。 我们想要根据设备修改序列化,这样当从移动设备访问时,服务应该只序列化一些重要的数据成员(不是全部) 我们这里有两个选择 为不同类型的设备创建单独的操作和数据协定 与实际的xml序列化混淆并抑制基于设备创建不必要的元素 我们不想使用第一个选项,因为它在将来引入了许多冗余代码问题 小型研究表明,我们需要使用IXmlSerializable并覆盖readXML()和writeXML()方法。 但与此同时,我已经看到DataContract和IXmlSerializable不应该一起使用的地方 任何搞乱实际序列化的例子都非常感谢。 [DataContract] public class TokenMessage { string tokenValue; string extraValue; [DataMember] public string Token { get { return tokenValue; } set { tokenValue = value; } } [DataMember] public string Extra { get { return extraValue; } set { extraValue = value; } } } 现在,当我从移动设备访问返回典型TokenMessage数据协定的服务时,我不希望序列化“额外”数据成员,即当我向操作合同提供不同的参数时,它应该能够序列化部分/全部数据成员(取决于操作) PS:现在请忽略设备检测部分。 […]

在.NET Core项目中找不到System.ServiceModel

我有一个.NET Core xUnit项目。 我试图从它调用WCF服务,但得到以下exception: System.InvalidOperationException occurred HResult=0x80131509 Message=An error occurred while loading attribute ‘ServiceContractAttribute’ on type ‘IMyContract’. Please see InnerException for more details. Inner Exception 1: FileNotFoundException: Could not load file or assembly ‘System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’. The system cannot find the file specified. 它适用于具有相同Nuget Package System.ServiceModel.Http.4.3.0的Framework 4.7项目。

我的ASMX代理方法中有哪些额外参数?

如果我将.NET 1.1客户端的Web引用添加到WCF服务,则客户端生成的代理方法包含一个额外的参数,以每个服务方法参数的后缀’Specified’结尾,例如 [OperationContract] string HelloWorld(string foo, int bar); 结果是: Service1.HelloWorld(string foo, bool fooSpecified, int bar, bool barSpecified); 我的服务参数不是可选的,所以客户端的这些额外参数是什么,我怎样才能摆脱它们?

WCF中的远程主机强制关闭现有连接

我有一个名为’Template’的抽象类,定义如下: [DataContract] public abstract class Template { [DataMember] public virtual int? Id { get; set; } [DataMember] public virtual string Title { get; set; } [DataMember] public virtual byte[] TemplateDoc { get; set; } [DataMember] public virtual bool IsSystemTemplate { get; set; } } 两个派生类:UserTemplate和SystemTemplate实现上面的抽象类,定义如下: public class UserTemplate : Template { [DataMember] public virtual Int32? […]

提供的URI方案“https”无效; 调用Web服务时需要’http’

我试图使用自定义C#代码从CRM工作流调用SharePoint Web服务。 但是,当我运行我的代码时,我收到以下错误: The provided URI scheme ‘https’ is invalid; expected ‘http’. Parameter name: via 这是违规代码: #region Set up security binding and service endpoint BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm; EndpointAddress endpoint = new EndpointAddress(endpointAddress); #endregion #region Create the client and supply appropriate credentials CopySPContents.CopyService.SharepointFileServiceClient client = new CopySPContents.CopyService.SharepointFileServiceClient(binding, endpoint); […]

什么是WCF中的WSDL URI?

什么是WSDL? 谷歌搜索时我找不到很多参考资料…… 我怎么知道我的WCF Web服务的WSDL URI?

System.Net.Http.HttpClient缓存行为

我正在使用NuGet的HttpClient 0.6.0。 我有以下C#代码: var client = new HttpClient(new WebRequestHandler() { CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable) }); client.GetAsync(“http://myservice/asdf”); 该服务(这次是CouchDB)返回ETag值和状态代码200 OK。 返回一个Cache-Control标头,其值为must-revalidate 更新,这是来自couchdb的响应头(取自visual studio调试器): Server: CouchDB/1.1.1 (Erlang OTP/R14B04) Etag: “1-27964df653cea4316d0acbab10fd9c04” Date: Fri, 09 Dec 2011 11:56:07 GMT Cache-Control: must-revalidate 下次我执行完全相同的请求时,HttpClient会执行条件请求并返回304 Not Modified。 哪个是对的。 但是,如果我使用具有相同CachePolicy的低级HttpWebRequest类,则第二次甚至不会发出请求。 这是我希望HttpClient也表现的方式。 它是必须重新validation的标头值还是为什么HttpClient表现不同? 我想只做一个请求,然后在没有条件请求的情况下从缓存中获取其余的请求。 (另外,作为附注,在调试时,响应状态代码显示为200 OK,即使服务返回304 Not Modified)