.NET WebService WebMethod 以自定义对象作为参数
我创建了一个 .NET WebService。我在那里实现了以下 WebMethod:
[WebMethod]
public string CheckLicense(License license) {
return "";
}
类型许可证来自不同的 Assembly X,我已将其引用到 WebService。许可证的完整类型是 Prayon.Shared.Library.Licensing.License
现在,我已经构建了一个也引用程序集 X 的客户端。当我尝试不使用 CheckLincense 调用 WebService 时:
private void CheckLicense(License license) {
using(var service = new Prayon.Service.Web.PrayonService()) {
service.CheckLicense(license);
}
}
service.CheckLicense() 想要一个 Type 的对象Prayon.Service.Prayon.Service.Web.License。 我不知道我做错了什么。我必须做什么才能将类型为 Prayon.Shared.Library.Licensing.License 的对象传递给 service.CheckLicense()?
I have created a .NET WebService. There I have implemented the following WebMethod:
[WebMethod]
public string CheckLicense(License license) {
return "";
}
The Type License comes from a different Assembly X which I have referenced to the WebService. The Fulltype of License is Prayon.Shared.Library.Licensing.License
Now, I have build a client which also references the Assembly X. When I try no to call the WebService with CheckLincense:
private void CheckLicense(License license) {
using(var service = new Prayon.Service.Web.PrayonService()) {
service.CheckLicense(license);
}
}
There service.CheckLicense() want an object of Type Prayon.Service.Prayon.Service.Web.License.
I don't know what I am doing wrong. What does I have to do, that I can pass a object of Type Prayon.Shared.Library.Licensing.License to service.CheckLicense()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想在许可证对象中使用方法,您需要:
调用您的 WebService,获取 service.License 对象,使用它创建本地 License 对象的实例,之后您将获得“本地”License 对象,其状态(属性)由您的 WebService 答案填充。
否则我不明白您为什么要使用“本地”许可证对象?
If you want to use a method in your License object you need to :
Call your WebService, obtain a service.License object, use it to create an instance of your local License object, after that you will have your 'local' License object with state (properties) filled by your WebService answer.
Otherwise i do not see why you would want to use a 'local' License object ?
您不应在 Web 服务和客户端之间共享程序集,而应从 Web 服务代理类型创建许可证实例(应在 service.x 中找到)
You should not share the assembly between your web service and your client but instead create an instance of your License from your web service proxy types (should be found into service.x)
您需要从 webserviceproxy 而不是从程序集创建一个实例。
当您从客户端添加对 Web 服务的服务引用时,它将为您生成代理类。在这些代理类中,您将定义许可证。使用它来创建实例并传递它,而不是直接从程序集中引用。
You need to create an instance from the webserviceproxy rather than from the asembly.
When you add a service reference to your webserice from the client it will generate proxy classes for you.Inside these you will have the License defined.use this to create an instance and pass it rather than referencing directly from your assembly.