Web服务正在返回一个对象,但它显示为null [英] Web service is returning an object but its showing as null

查看:80
本文介绍了Web服务正在返回一个对象,但它显示为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



在我的应用程序中,我添加了一个Web服务作为参考。我能够访问服务公开的功能。从服务中,函数返回一个对象。



我的问题是当我将该函数的响应变为一个对象时,它变为空。



Web服务有一个函数Ge​​tPassword(字符串),它返回一个类UserDetails的对象





我添加了Web服务作为参考我能够看到GetPassword()和UserDetails类。



Hello

In my application I have added a web service as reference. I am able to access the function which is exposed by the service. From the service the function is returning an object.

My issue is when I take the response of that function into an object its getting as null.

Web service has a function GetPassword(string) and it is returning an object of Class UserDetails


I have added web Service as reference and I am able to see both GetPassword() and UserDetails Class.

But

UserDetails obj = GetPassword("123") returns null.





如果我将函数GetPassword的返回类型更改为字符串类型它的工作原理。



相同具有返回类型对象的服务在Soapui中工作。





任何人都可以建议解决方案请



If I change the return type of the function GetPassword to string type its working.

The same service with return type object is working in Soapui.


Any one can suggest a solution please

推荐答案

可能的问题在于命名空间。由于您没有发布源代码,因此无法确定原因。


考虑创建类UserDetails的场景。您将该类定义复制到Web服务和ASP.Net应用程序。接下来,您尝试编译您的probject,并对一个异常表示惊讶,该异常表示WebServiceName.Person无法隐式转换为WebAppName.Person。



它们都是根据确切类的副本创建的。如您所见,问题在于名称空间。虽然它们可能是相同的类,但它们不是同一类。



阅读文章(下面提供的链接以及如何在webservice中使用自定义类的示例)



http: //www.dalepreston.com/Blog/2005/02/returning-custom-classes-from-web.html [ ^ ]



欢呼
The probable problem is with the namespaces. As you didn't post the source it is not possible to find out the exact reason.

Considering the scenario where you create a class UserDetails . You copy that class definition to your web service and to your ASP.Net application. Next you try to compile your probject and are surprised by an exception that says WebServiceName.Person cannot be implicitly converted to WebAppName.Person.

They are both created from copies of the exact class. The problem, as you can see, is in the namespaces. While they may be identical classes, they are not the same class.

Read the article (link provided below with example how you can use custom class in webservice)

http://www.dalepreston.com/Blog/2005/02/returning-custom-classes-from-web.html[^]

cheers


检查下面提到的链接。可能对你有帮助。



如何从Web服务返回用户定义的对象



C#.NET WebService返回对象



我希望这会有帮助给你。
Check the below mentioned links.It may be helped to you.

How to Return a User Defined Object from Webservice

C#.NET WebService returning object

I hope this will help to you.


这篇关于Web服务正在返回一个对象,但它显示为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆