从 C++ 调用 webmethod

发布于 2024-07-16 05:19:25 字数 870 浏览 11 评论 0原文

我正在从 C++ 调用 webmethod。 [webmthod] 定义如下

[WebMethod]
public string UploadFile(byte[] data)

这是我在 C++ 中的调用方式

 static TCHAR hdrs[] = "Content-Type: application/x-www-form-urlencoded";
     static TCHAR frmdata[] = "data=temp.txt";
  HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  HINTERNET hConnect = InternetConnect(hSession, "localhost",
      INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
  HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "my/WebService.asmx/UploadFile", NULL, NULL, 0, 0, 1);
  HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));

: 我收到以下错误。

System.ArgumentException:无法将 temp.txt 转换为 System.Byte。

那么如何传入 frmdata[] 以便将其转换为 Web 服务上的 System.byte 呢?

谢谢!

I am calling a webmethod from C++. The [webmthod] is defined as follows

[WebMethod]
public string UploadFile(byte[] data)

Here is how I call it in C++

 static TCHAR hdrs[] = "Content-Type: application/x-www-form-urlencoded";
     static TCHAR frmdata[] = "data=temp.txt";
  HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  HINTERNET hConnect = InternetConnect(hSession, "localhost",
      INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
  HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "my/WebService.asmx/UploadFile", NULL, NULL, 0, 0, 1);
  HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));

With this; I receive the following error.

System.ArgumentException: Cannot convert temp.txt to System.Byte.

So how do I pass in the frmdata[] so that it can be converted to a System.byte on the webservice?

Thanks!

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

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

发布评论

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

评论(2

树深时见影 2024-07-23 05:19:26

我最终从 C++ 进行 HTTP 上传..

I ended up doing HTTP UPLOAD from C++..

东北女汉子 2024-07-23 05:19:26

供将来参考:考虑使用 ATL Server。 您可以在 www.codeplex.com/AtlServer(Microsoft 将 ATL Server 从最新的 ATL 9.0 SDK 中删除并将其移至 codeplex)和 MSDN 上找到最新信息和更多信息:msdn.microsoft.com/en-us/library/exb5b09w (VS.80).aspx

对于 C++,您可以生成一个代理头文件,该文件整齐地包装了使用 ATL Soap 和您希望的任何 ATL Soap 客户端(WinInet、WinHTTP、Soap Socket 等)调用 Web 方法所需的所有内容,该客户端处理所有内容网络呼叫。 要生成此文件,您可以使用sproxy.exe工具。 那么Web方法调用就变成了简单的类方法调用。

参考:msdn.microsoft.com/en-us/library/994721ak(VS.80).aspx
Sproxy 工具:msdn.microsoft.com/en-us/library/ztta389h(VS.80).aspx
WS 调用示例:msdn.microsoft.com/en-us/library/ftdya1d6(VS.80).aspx

For future reference: consider using ATL Server. You can find latest bits and more information on www.codeplex.com/AtlServer (Microsoft pulled ATL Server out of latest ATL 9.0 SDK and moved it to codeplex), and MSDN: msdn.microsoft.com/en-us/library/exb5b09w(VS.80).aspx

For C++ you can generate a proxy header file that neatly wraps all you need to call the web method using ATL soap and whatever ATL Soap Client you wish (WinInet, WinHTTP, Soap Socket, etc) which handles all the network calls. To generate this file, you can use sproxy.exe tool. Then the web method call becomes a simple class method call.

Reference: msdn.microsoft.com/en-us/library/994721ak(VS.80).aspx
Sproxy Tool: msdn.microsoft.com/en-us/library/ztta389h(VS.80).aspx
Example WS call: msdn.microsoft.com/en-us/library/ftdya1d6(VS.80).aspx

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