[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

returning an object from a web service

Khurram Lone

1/14/2003 3:24:00 PM

Hi

I am trying to return an object obj1 from a web service
(ws1). When I
add a reference to a client (localhost1) and call the web
service, it
returns the object of type localhost1.obj1 rather than
obj1, and it
cannot be type casted back to obj1. Is there any way I
can make the
web service return the object of the type obj1?

Thanks

3 Answers

Pierre Greborio

1/14/2003 3:34:00 PM

0

localhost1 is the default namespace generated by the wsdl (or vs.net with
add reference) you can change it right cliccking on the reference
(localhost1) and renaming it.

Pierre

--
-----------------------------------------------------------
Pierre Greborio
http://www.ugi...
-----------------------------------------------------------
"Khurram Lone" <klone@cfsloans.com> wrote in message
news:45dc01c2bbd8$b475e330$d5f82ecf@TK2MSFTNGXA12...
> Hi
>
> I am trying to return an object obj1 from a web service
> (ws1). When I
> add a reference to a client (localhost1) and call the web
> service, it
> returns the object of type localhost1.obj1 rather than
> obj1, and it
> cannot be type casted back to obj1. Is there any way I
> can make the
> web service return the object of the type obj1?
>
> Thanks
>


Doug&Cindy

1/14/2003 8:22:00 PM

0

I think what you want is serialization....your client library has an object
(objDOG) and your webservice returns a type of mywebservername.objDOG.
Unless your server and client share the same library the objects are
completely different. What you can do is look into making it
XMLSerializable....I belive you can serialize the mywebservername.objDOG and
deserialize it into your objDOG...

hth
doug
"Khurram Lone" <klone@cfsloans.com> wrote in message
news:45dc01c2bbd8$b475e330$d5f82ecf@TK2MSFTNGXA12...
> Hi
>
> I am trying to return an object obj1 from a web service
> (ws1). When I
> add a reference to a client (localhost1) and call the web
> service, it
> returns the object of type localhost1.obj1 rather than
> obj1, and it
> cannot be type casted back to obj1. Is there any way I
> can make the
> web service return the object of the type obj1?
>
> Thanks
>


Yasser Shohoud [MS]

1/14/2003 11:40:00 PM

0

Khurram,

Web Services do not preserve the .NET type fidelity of WebMethod parameters.
The parameters are serialized per the serialization rules documented at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/c...
l/cpconserialization.asp?frame=true. The reason is that Web Services must
be type system agnostic. a Java client could not call a VB.NET Web Service
if the VB types, which Java could not use, were passed across. Web Service
types are expressed as XSD in WSDL. The .NET proxy generation tools take
the parameter description from the WSDL and come up with the closest type
they can into which the XML described in the WSDL can be deserialized. To
get back to the orginal type in a .NET client you can do the following:

1. You can explicitly convert the proxy type to the desired type. In C#,
you can do this by creating a conversion operator.
2. You can also simply modify the generated proxy code and replace the
default Web Method types with the original ones from the Web Service. The
proxy will deserialize the XML it gets into the type you want. For example,
a Web Service that returns an Array list will cause a proxy method to be
generated that returns an object array. You can modfy the Proxy method to
use an ArrayList (the original type) instead by changing it from:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http:/...
rg/GetArrayList", RequestNamespace="http:/...rg/",
ResponseNamespace="http:/...rg/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

public object[] GetArrayList() {

object[] results = this.Invoke("GetArrayList", new object[0]);

return ((object[] )(results[0]));

}



To

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http:/...
rg/GetArrayList", RequestNamespace="http:/...rg/",
ResponseNamespace="http:/...rg/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

public ArrayList GetArrayList() {

object[] results = this.Invoke("GetArrayList", new object[0]);

return ((ArrayList)(results[0]));

}


Martin

--
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Khurram Lone" <klone@cfsloans.com> wrote in message
news:45dc01c2bbd8$b475e330$d5f82ecf@TK2MSFTNGXA12...
> Hi
>
> I am trying to return an object obj1 from a web service
> (ws1). When I
> add a reference to a client (localhost1) and call the web
> service, it
> returns the object of type localhost1.obj1 rather than
> obj1, and it
> cannot be type casted back to obj1. Is there any way I
> can make the
> web service return the object of the type obj1?
>
> Thanks
>