简体   繁体   English

NET的HTTP POST复杂请求

[英]HTTP POST complex requests with .NET

I have a Web Service method developed using .NET 3.5 (VS2008) which expects a few strings (username, password, subject, file type) and a binary document coded in Base64. 我有一个使用.NET 3.5(VS2008)开发的Web服务方法,该方法需要一些字符串(用户名,密码,主题,文件类型)和以Base64编码的二进制文档。

I enabled both SOAP and HTTP POST. 我同时启用了SOAP和HTTP POST。 While SOAP works perfectly, it is not possible to send HTTP POST requests. 虽然SOAP可以完美运行,但是无法发送HTTP POST请求。 The server responses with "Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1". 服务器响应“服务器无法处理请求。--->根级别的数据无效。第1行,位置1”。

Customers are using this method to upload their documents from their applications. 客户正在使用此方法从其应用程序上载其文档。

I was told that .NET does not support complex structures using HTTP POST. 有人告诉我.NET不支持使用HTTP POST的复杂结构。 Any way to support this? 有什么方法可以支持这个吗?

.NET does support complex structures using POX (plain old xml) with the httpBinding. .NET确实使用带有httpBinding的POX(纯老式xml)支持复杂的结构。 Here is an article that explains how to set it up: http://fluxcapacity.net/2007/11/06/how-to-create-restpox-web-services-with-wcf/ 这是一篇介绍其设置方法的文章: http : //fluxcapacity.net/2007/11/06/how-to-create-restpox-web-services-with-wcf/

Note: All SOAP, XML and JSON dto updates still work over HTTP POST - SOAP just wraps your payload with additional markup, which effectively just adds additional overhead and complexity for website (ie Ajax) clients. 注意:所有SOAP,XML和JSON dto更新仍然可以通过HTTP POST进行工作-SOAP只是使用其他标记来包装您的有效负载,这实际上只会增加网站(即Ajax)客户端的额外开销和复杂性。

If you want your same webservice to work over SOAP as well as other endpoints eg XML or JSON you may be interested in this opensource webservices framework which enables all these endpoints without any additional configuration. 如果您希望同一个Web服务可以通过SOAP以及其他端点(例如XML或JSON)运行,那么您可能会对这种开放源Web服务框架感兴趣,该框架无需任何其他配置即可启用所有这些端点。

It sounds like you want to shift from a desktop app to an asp web based application. 听起来您想从桌面应用程序转换为基于ASP Web的应用程序。

While that is usually a great idea I think you will be fighting an uphill battle in trying to post files via http/form to your web service. 虽然通常这是一个好主意,但我认为您将在尝试通过http / form将文件发布到Web服务方面进行艰苦的战斗。 While technically it is possible I am having a hard time thinking of an implementation. 从技术上讲,我可能很难考虑实现。

You might have better luck using a form as a proxy with your input variables and a file input to submit to a form, eg a webform, and use the codebehind on the webform to spin up an instance of your webservice class (no need to use a proxy, you are already on your side of the wire). 您可能会比较幸运,可以将表单用作输入变量和文件输入的代理,以提交到表单(例如,Web表单),并使用Web表单上的代码来启动您的Webservice类的实例(无需使用代理,那么您已经站在一边了)。

If this does not make sense let me know and if it cannot be made to fit your scenario please update your question to more clearly state your desired outcome. 如果这没有任何意义,请告知我,如果无法根据您的情况进行,请更新您的问题以更清楚地说明您想要的结果。

If you are doing this via Ajax decorate your service class with [ScriptService] attribute and post JSON via xmlhttp. 如果通过Ajax执行此操作,请使用[ScriptService]属性装饰您的服务类,并通过xmlhttp发布JSON。 You can easily send complex arguments. 您可以轻松发送复杂的参数。

see http://www.codeproject.com/Articles/38999/Consuming-ASP-net-WebServices-WCF-Services-and-sta.aspx for instructions. 有关说明,请参见http://www.codeproject.com/Articles/38999/Consuming-ASP-net-WebServices-WCF-Services-and-sta.aspx

If you are not, please elaborate on what is doing the posting and how you are packing the data. 如果不是,请详细说明发布过程以及如何打包数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM