Tag: web services

更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxArrayLength属性

在向C#服务发送(或接收)字节数组时,我遇到以下exception。 There was an error deserializing the object of type System.Byte[]. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 6, position 34838.’. Please see InnerException for more details 据我所知,XmlDictionaryreader是由webservice自动创建的。 […]

如何将List 传递给服务引用(C#,VS2008)

我遇到的问题是我创建了一个Web服务和一个Windows窗体(单独的解决方案)。 我使用服务引用将web服务添加到表单应用程序,我可以将“int”或“字符串”传递给Web服务没问题,但我无法传递int或List <int >的数组 Web服务代码如下: using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Web.Services; namespace CalculateService { [WebService(Namespace = “http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class Service1 : System.Web.Services.WebService { [WebMethod] public int CalcluateSum(List listInt) { int sum = listInt.Sum(); return sum; } } } 并且客户端代码是: using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; […]

通过ASMX Web服务进行序列化时保持空格/换行符

我正在ASMX Webservice(Legacy .NET SOAP Service)中对XML文档进行一些预处理,以便最终在Silverlight前端使用。 我正在将该XML文档处理为POCO对象以便于使用。 该对象定义如下: public class CACDocument : ITextDocument { #region Properties public string Title { get; set; } public string Text { get; set; } public List CodeList { get; set; } public XElement FormatedText { get; set; } #endregion #region Constructor public CACDocument() { CodeList = new List(); } #endregion […]

通过HttpClient使用外部REST Web服务的存储库模式示例?

我已经搜索了很多,但没有找到任何使用存储库模式在ASP.NET MVC应用程序中使用外部REST Web服务的良好示例,具有松散耦合和有意义的关注点分离。 我在网上找到的几乎所有存储库模式的例子都是编写SQL数据或使用ORM。 我只想看一些使用HttpClient检索数据但包装在存储库中的示例。 有没有提到好的例子? 或者有人可以写一个简单的例子吗?

Bitstamp – C#中的新身份validation – 签名

bitstamp的新身份validation说明如下: Signature是HMAC-SHA256编码的消息,包含:nonce,客户端ID和API密钥。 必须使用通过API密钥生成的密钥生成HMAC-SHA256代码。 此代码必须转换为hex表示forms(64个大写字符)。示例(Python):message = nonce + client_id + api_key signature = hmac.new(API_SECRET,msg = message,digestmod = hashlib.sha256).hexdigest()。上() 来源: 链接 我有以下代码来添加新签名(和其他参数): public void AddApiAuthentication(RestRequest restRequest) { var nonce = DateTime.Now.Ticks; var signature = GetSignature(nonce, apiKey, apiSecret, clientId); restRequest.AddParameter(“key”, apiKey); restRequest.AddParameter(“signature”, signature); restRequest.AddParameter(“nonce”, nonce); } private string GetSignature(long nonce, string key, string secret, string clientId) { string […]

Web服务在单声道4中不起作用

我有一个使用Web服务与ASP.Net的应用程序,我应该维护。 所以我在这个主题上提高了我的技能。 我在使用VS 2013的Window中运行Webservice没有问题,但是有单声道问题。 这是我运行代码时遇到的错误 System.ArgumentNullException Value cannot be null. Parameter name: path1 Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): mscorlib. Exception stack trace: at System.IO.Path.Combine (System.String path1, System.String path2) [0x00006] in :0 at System.Web.Services.Configuration.WsdlHelpGeneratorElement.get_HelpGeneratorPath () [0x0000c] in :0 at System.Web.Services.Protocols.DocumentationServerProtocol.Initialize () [0x001f1] in :0 at System.Web.Services.Protocols.ServerProtocol.SetContext […]

生成的服务引用会抛出什么exception?

我使用“添加服务引用…”在Visual Studio 2010中添加了一个Web服务。 这会在名为Reference.cs的文件中生成一些代码。 现在,如果我调用其中一种方法,我就不知道该方法可能抛出的exception。 据推测,它可以抛出网络相关的exception,如SocketException或IOException ? 可以在msdn或源代码内部检查.NET中的常规方法,以揭示可能抛出的exception,例如File.Open 。 这里很清楚我应该捕获哪些exception并重新抛出以在稍后阶段显示错误消息。 对于那些生成的方法,我怎么知道它们可能抛出的exception?

如何在C#中将XMLDocument反序列化为对象?

我有一个.Net webserivce,它接受字符串格式的XML 。 发送到webserivce的XML String可以表示系统中的任何Object。 我需要检查第一个节点,找出反序列化XML字符串的对象。 为此,我将不得不将XML加载到XMLDocument (不想使用RegEx或字符串比较)。 我想知道是否有一种方法来反序列化XMLDocument/XMLNode而不是反序列化字符串以节省一些性能? 串行化XMLNode而不是字符串是否会带来任何性能优势? 加载XMLDocument的方法 public void LoadFromString(String s) { m_XmlDoc = new XmlDocument(); m_XmlDoc.LoadXml(s); } 谢谢

如何将web api用作Web服务?

我已经创建了一个测试ASP.Net Web Api,现在我想知道如何在Windows窗体应用程序中将它用作Web服务? 当前url为http://localhost:59682 ,当我添加http://localhost:59682或http://localhost:59682/api/或http://localhost:59682/api/products/作为网络服务参考时我收到此错误: There was an error downloading ‘http://localhost:59682/api/products/$metadata’. The request failed with HTTP status 400: Bad Request. Metadata contains a reference that cannot be resolved: ‘http://localhost:59682/api/products/’. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (405) Method Not Allowed. If the service is defined […]

将自定义对象传递给Web服务

我需要将自定义对象传递给远程Web服务。 我已经读过可能有必要实现ISerializable,但我已经这样做了,而且遇到了困难。 C#将自定义对象传递给Web服务方法的正确方法是什么?