如何在应用程序中添加对Web服务公共结构的引用

发布于 2024-09-05 23:00:03 字数 790 浏览 4 评论 0原文

最初发布于: http://www.experts-exchange.com/Programming/Languages/ C_Sharp/Q_21355401.html

我有一个包含两个项目的解决方案:一个 Web 服务项目和一个 Web 应用程序项目,该项目具有对 Web 服务项目的 Web 引用(Web 应用程序项目只是一个测试用例)。

我的 Web 服务项目包含一个包含多个公共结构的类文件。我可以在 Web 服务项目本身中很好地使用这些。但是,我无法在 Web 应用程序项目中查看或引用结构。

当您向 Web 服务添加 Web 引用时,您实际上获得了该 Web 服务的“对象”版本,这不是真的吗?在这种情况下,我希望能够访问网络服务的任何公共成员。

我之前创建了引用关联项目的服务,当我使用该服务时,我可以访问引用的项目及其成员。为什么我无权访问与服务位于同一项目中的类文件?

Web 服务 (asmx) 和类文件 (cs) 的命名空间是相同的。在网络应用程序中,我有一个用于网络参考的 using 语句。我确实可以从 asmx 访问 webmethods,但不能访问关联的类文件及其公共成员...

我也遇到了同样的问题,谁能告诉我解决办法吗? 我想发送 WebService 上公开可用的参数结构列表。

Originally posted on:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21355401.html

I have a solution containing two projects: a webservice project and a web app project which has a web reference to the webservice project (the web app project is simply a test case).

My webservice project includes a class file containing multiple public structs. I can use these just fine from within the webservice project itself. However, I'm not able to see or reference the structs from within the web app project.

Isn't it true that when you add a web reference to a web service, you essentially get an "object" version of the webservice? In that case I expect to be able to access any public members of the webservice.

I have previously created services that reference associated projects, and when I consume the service, I have access to the referenced projects and their members. Why don't I have access to a class file that's in the same project as the service?

The Namespace for the webservice (asmx) and the class file (cs) are the same. In the web app, I have a using statement for the web reference. I DO have access to the webmethods from the asmx, just not the associated class files and their public members...

I'm having the same problem, someone could tell me what's the solution?
I would like to send a list of parameter struct publicly available on the WebService.

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

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

发布评论

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

评论(1

输什么也不输骨气 2024-09-12 23:00:03

首先,您应该使用 WCF 而不是 ASMX Web 服务来进行所有新开发。

其次,当您添加 Web 引用(或者最好是服务引用)时,您将获得 Web 服务公开的所有类型的代理副本。如果服务返回一个包含某种结构类型的公共属性的类,那么您将获得返回类的代理副本以及该结构类型的代理副本。

顺便说一句,你会得到一个类,而不是一个结构。 “结构”的概念不能跨越服务边界。

First of all, you should be using WCF instead of ASMX web services for all new development.

Second, when you add a Web Reference (or, preferably a Service Reference), you get proxy copies of all the types exposed by the web service. If the service returns a class that contains a public property of some struct type, then you will get a proxy copy of the returned class, as well as a proxy copy of the struct type.

You'll get a class, BTW, not a struct. The concept of "struct" doesn't translate across service boundaries.

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