如何增加 ASMX Web 服务的 POST 大小?

发布于 2024-10-13 10:06:31 字数 1437 浏览 4 评论 0原文

背景

我正在开发一个 ASP.Net 服务器端控件,需要与 ASMX Web 服务通信。服务器端控件使用 WebClient 对象与 Web 服务通信,因为它需要在各种应用程序中经常重用,并且为了使开发人员更容易,他们不需要创建服务对网络服务的引用。

实现

在该控件的使用过程中,需要发送一个序列化的对象到Web服务。该对象使用 XmlSerializer 进行序列化,然后使用 chilkat 压缩库压缩生成的 XML 字符串。该控件的 Web 服务调用如下所示:

webClient.UploadStringAsync(new Uri(serviceHost + serviceMethod), "POST", sendData)

sendData (string) 的内容为 compressedResponse={CompressedData}代码>.

Web 服务具有如下定义的方法来接收数据,然后使用 chilkat 库解压缩字符串值,然后使用 XmlSerializer 反序列化对象。

public void SaveResponse(字符串压缩响应)

控件和服务之间的通信正常。最初,web.config 中没有为上述任何内容定义设置或绑定。经过初步搜索后我确实添加了

到客户端和服务器 web.config 文件。这没有什么区别。

问题

sendData 变量中压缩或解压缩发布到 Web 服务的数据对于正常的 POST 请求来说太大,并且已损坏。在以压缩格式将字符串发布到服务器之前和之后检查字符串的最后几个字符时,可以确认这一点,并且在未压缩的情况下,在调试器中检查时,Xml 文档缺少最后一个根标记。 string 无法解压,因此每次服务调用都会失败。

如何增加 WebClient 请求的 POST 大小以确保服务器收到完整的字符串?

我已经查看了 Google 上的各种选项,但没有一个有效给我一个足够好的样本来说明在哪里进行更改,或者更改需要是什么样子的样本。我完全不知道是否需要在服务器或消费网站上进行更改,并且由于没有为此定义绑定,因此如何在 web.config 中为ASMX HTTP 服务调用。

Background

I am developing an ASP.Net server side control that needs to talk to an ASMX web service. The server side control uses a WebClient object to talk to the web service, since it needs to be reused often in various application, and to make it easier on the developers, they are not required to create a service reference to the web service.

Implementation

During the use of the control, it is requires the sending of a serialised object to the web service. The object is serialised using the XmlSerializer and the resulting XML string is then compressed using the chilkat compression library. The web service call for the control looks as follows:

webClient.UploadStringAsync(new Uri(serviceHost + serviceMethod), "POST", sendData)

The content of sendData (string) is compressedResponse={CompressedData}.

The web service has a method defined as follows to receive the data and then decompress the string value using the chilkat library before de-serialising the object using the XmlSerializer.

public void SaveResponse(string compressedResponse)

The communication between the control and the service is working. Initially there were no settings or binding defined in the web.config for any of the above. After initial searching I did add

<httpRuntime maxRequestLength="20480"/>

to both the client and server web.config files. This has made no difference.

Problem

Compressed or uncompressed the data being posted to the web service in the sendData variable is to big for a normal POST request, and is corrupted. This is confirmed when checking the last few characters of the string before and after it being posted to the server in compressed format, and uncompressed, the Xml document is missing the last root tag when checking in the debugger. The string can't be decompressed and therefore the service call fails every time.

How do I increase the POST size for the WebClient request to ensure that the full string is received by the server?

I have looked at the various option on Google, but none are giving me a good enough sample of where to make the changes, or samples of what the changes need to look like. I am completely lost as to whether the change needs to be made on the server or the consuming website, and since there are no binding defined for this, how to create a binding in the web.config for an ASMX HTTP service call.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

︶葆Ⅱㄣ 2024-10-20 10:06:31

我相信您一定达到了 ASP.NET 最大请求长度限制。您可以通过配置文件进行修改,例如:

<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>

maxRequestLength 值以 KB 为单位,因此上述设置将允许 20 MB。您还可以使用位置标签仅将设置应用于选定的 URL,例如

<location path="yourservice.asmx">
    <system.web>
        <httpRuntime executionTimeout="240" maxRequestLength="20480" />
    </system.web>
</location>

I believe you must be hitting ASP.NET max request length limit. That you can modify via config file such as:

<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>

maxRequestLength value is in KB, so above setting would allow 20 MB. You can also apply the setting only to selected URLs using location tag e.g.

<location path="yourservice.asmx">
    <system.web>
        <httpRuntime executionTimeout="240" maxRequestLength="20480" />
    </system.web>
</location>
去了角落 2024-10-20 10:06:31

仅启用 HttpPost 时,似乎无法更改 ASMX Web 服务的 POST 大小。

最终的解决方案是将服务切换到运行 HttpSoap 并创建对包含控件的程序集的服务引用。完成后,一旦通过属性设置端点,就会使用控件中的代码创建绑定。

There seems to be no way to change the POST size for a ASMX Web Service when only HttpPost is enabled.

The solution in the end was to switch the service to running HttpSoap and create a service reference to the assembly containing the control. Once done the binding is created using code in the control once the endpoint is set via a property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文