如何从 Web 服务返回或转换相同类型
我在 asp.net (ASMX) 中创建了一个 Web 服务用于缓存目的。 使用此 WS 的网站请求并获取共享类型对象(即,网站和 Web 服务都使用包含该对象类型的相同 DLL)。
但发生的情况是,网站从 Web 服务获取响应,并且类型由 WS 的名称空间包装。
例如。 如果我在共享 DLL 中有一个类 Core.Person Web 服务返回 Core.Person。 网站(即使它知道 core.person)将获得 WebServiceNS.Person
这不允许我投射它。
从 WS 获取这些对象时,如何仍然使用相同的原始 DLL 命名空间?
谢谢
I've created a web service in asp.net (ASMX) for caching purposes.
The website that uses this WS, requests and gets a shared type object (that is, both the website & webservices use the same DLL that includes that object type).
but what happens is, that the website gets the response from the webservices and the type is being wrapped by the WS's name space.
for instance.
If I have in the shared DLL a class Core.Person
the webservice returns Core.Person.
the website (even it knows the core.person) will get WebServiceNS.Person
This won't allow me to cast it.
how can I still use the same original DLL namespace when getting those objects from the WS?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种解决方案是使用 WCF 服务代替 ASMX 服务。 WCF 服务允许您使用现有结构进行 Web 服务调用。在这种情况下,您将不需要创建服务的引用。您可以在这两个项目中使用相同的
Core.dll
。如果您需要任何帮助,请发表评论。
希望这对你有用。
One solution can be, instead of using ASMX service use WCF service. WCF service allows you to use existing structure for the webservice call. In that case you will not need to create reference of your service. You can use same
Core.dll
in both the projects.If you need any help in this, post a comment.
Hope this works for you.
实际上,当我们添加 Web 服务引用时,VS 会生成一个存根,为 WS 所需的所有对象创建类。 (这些基于 Web 服务器上托管的 WSDL 文件)。我们与网络服务的所有通信都是使用这个存根完成的。我想你必须编写自己的 副本构造函数为此。
Actually when we add a webservice reference VS generates a stub creating classes for all the objects required by WS. (These are on the basis of WSDL file hosted on the web server). All our communication with the webservice is done using this stub. I guess you'll have to write your own copy constructor for this.
您不应该使用 ASMX 服务进行新开发。这是一项传统技术。
此外,它没有能力做你想做的事。另一方面,WCF 可以轻松完成此任务。
You should not be using ASMX services for new development. It's a legacy technology.
In addition, it has no ability to do what you want. WCF, on the other hand, can do it trivially.