Groups > Asp .Net > ASP.NET XML Web Services > Re: Simple web service with User Object parameter




Simple web service with User Object parameter

Simple web service with User Object parameter
Wed, 2 Apr 2008 14:44:22 +0000
I am trying create a simple web service in Visual Studio 2008 and pass a 
custom object.

I am creating the proxy to this service using the "Add WebReference' ...

but in the end... I always get type mis-match problems on the client side.

Can someone point me in the right direction?  




        /* Server */

        [WebMethod]
        public UserMessage HelloWorld2(string clientmessage)
        {
            UserMessage result = new UserMessage();
            result.Message1 = "hello: " + clientmessage;
            result.Message2 = "there";

            return result; 
        }

/* and USER message is defined as in a .dll of its own which is referenced 
   by both client and server*/


    public class UserMessage
    {
        public UserMessage() { }

        public string Message1 { get; set; }

        public string Message2 { get; set; }
    }

/* and the client is: */
protected void Page_Load(object sender, EventArgs e)
    {
        localhost.WebService1 proxy = new localhost.WebService1();

        UserMessage umsg = proxy.HelloWorld2("I am the client");
        /* type mismatch here */

        
    }
Post Reply
Re: Simple web service with User Object parameter
Thu, 3 Apr 2008 13:53:58 +0000
Here is the wsdl..... greeek to me.  thanks. 

 <?xmlversion="1.0"encoding="utf-8"?>

<wsdl:definitionsxmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"xmlns:soapenc=&
quot;http://schemas.xmlsoap.org/soap/encoding/"xmlns:mime="http://sche
mas.xmlsoap.org/wsdl/mime/"xmlns:tns="http://tempuri.org/"xmlns:s
="http://www.w3.org/2001/XMLSchema"xmlns:soap12="http://schemas.x
mlsoap.org/wsdl/soap12/"xmlns:http="http://schemas.xmlsoap.org/wsdl/ht
tp/"targetNamespace="http://tempuri.org/"xmlns:wsdl="http://
schemas.xmlsoap.org/wsdl/"><wsdl:types>

<s:schemaelementFormDefault="qualified"targetNamespace="http:/
/tempuri.org/"><s:elementname="HelloWorld2">

<s:complexType><s:sequence>

<s:elementminOccurs="0"maxOccurs="1"name="clientmess
age"type="s:string" /></s:sequence>

</s:complexType></s:element>

<s:elementname="HelloWorld2Response"><s:complexType>

<s:sequence><s:elementminOccurs="0"maxOccurs="1"nam
e="HelloWorld2Result"type="tns:UserMessage" />

</s:sequence></s:complexType>

</s:element><s:complexTypename="UserMessage">

<s:sequence><s:elementminOccurs="0"maxOccurs="1"nam
e="Message1"type="s:string" />

<s:elementminOccurs="0"maxOccurs="1"name="Message2&q
uot;type="s:string" /></s:sequence>

</s:complexType><s:elementname="UserMessage"nillable="tr
ue"type="tns:UserMessage" />

</s:schema></wsdl:types>

<wsdl:messagename="HelloWorld2SoapIn"><wsdl:partname="pa
rameters"element="tns:HelloWorld2" />

</wsdl:message><wsdl:messagename="HelloWorld2SoapOut">

<wsdl:partname="parameters"element="tns:HelloWorld2Response&qu
ot; /></wsdl:message>

<wsdl:messagename="HelloWorld2HttpGetIn"><wsdl:partname="
;clientmessage"type="s:string" />

</wsdl:message><wsdl:messagename="HelloWorld2HttpGetOut">

<wsdl:partname="Body"element="tns:UserMessage"
/></wsdl:message>

<wsdl:messagename="HelloWorld2HttpPostIn"><wsdl:partname=&quo
t;clientmessage"type="s:string" />

</wsdl:message><wsdl:messagename="HelloWorld2HttpPostOut">


<wsdl:partname="Body"element="tns:UserMessage"
/></wsdl:message>

<wsdl:portTypename="WebService1Soap"><wsdl:operationname=&quo
t;HelloWorld2">

<wsdl:inputmessage="tns:HelloWorld2SoapIn"
/><wsdl:outputmessage="tns:HelloWorld2SoapOut" />

</wsdl:operation></wsdl:portType>

<wsdl:portTypename="WebService1HttpGet"><wsdl:operationname=&
quot;HelloWorld2">

<wsdl:inputmessage="tns:HelloWorld2HttpGetIn"
/><wsdl:outputmessage="tns:HelloWorld2HttpGetOut" />

</wsdl:operation></wsdl:portType>

<wsdl:portTypename="WebService1HttpPost"><wsdl:operationname=
"HelloWorld2">

<wsdl:inputmessage="tns:HelloWorld2HttpPostIn"
/><wsdl:outputmessage="tns:HelloWorld2HttpPostOut" />

</wsdl:operation></wsdl:portType>

<wsdl:bindingname="WebService1Soap"type="tns:WebService1Soap&q
uot;><soap:bindingtransport="http://schemas.xmlsoap.org/soap/http&quo
t; />

<wsdl:operationname="HelloWorld2"><soap:operationsoapAction=&
quot;http://tempuri.org/HelloWorld2"style="document" />

<wsdl:input><soap:bodyuse="literal" />

</wsdl:input><wsdl:output>

<soap:bodyuse="literal" /></wsdl:output>

</wsdl:operation></wsdl:binding>

<wsdl:bindingname="WebService1Soap12"type="tns:WebService1Soap
"><soap12:bindingtransport="http://schemas.xmlsoap.org/soap/http
" />

<wsdl:operationname="HelloWorld2"><soap12:operationsoapAction
="http://tempuri.org/HelloWorld2"style="document" />

<wsdl:input><soap12:bodyuse="literal" />

</wsdl:input><wsdl:output>

<soap12:bodyuse="literal" /></wsdl:output>

</wsdl:operation></wsdl:binding>

<wsdl:bindingname="WebService1HttpGet"type="tns:WebService1Htt
pGet"><http:bindingverb="GET" />

<wsdl:operationname="HelloWorld2"><http:operationlocation=&qu
ot;/HelloWorld2" />

<wsdl:input><http:urlEncoded />

</wsdl:input><wsdl:output>

<mime:mimeXmlpart="Body" /></wsdl:output>

</wsdl:operation></wsdl:binding>

<wsdl:bindingname="WebService1HttpPost"type="tns:WebService1Ht
tpPost"><http:bindingverb="POST" />

<wsdl:operationname="HelloWorld2"><http:operationlocation=&qu
ot;/HelloWorld2" />

<wsdl:input><mime:contenttype="application/x-www-form-urlencoded&q
uot; />

</wsdl:input><wsdl:output>

<mime:mimeXmlpart="Body" /></wsdl:output>

</wsdl:operation></wsdl:binding>

<wsdl:servicename="WebService1"><wsdl:portname="WebServi
ce1Soap"binding="tns:WebService1Soap">

<soap:addresslocation="http://localhost:53988/WebService1.asmx"
/></wsdl:port>

<wsdl:portname="WebService1Soap12"binding="tns:WebService1Soap
12"><soap12:addresslocation="http://localhost:53988/WebService1.
asmx" />

</wsdl:port><wsdl:portname="WebService1HttpGet"binding="
tns:WebService1HttpGet">

<http:addresslocation="http://localhost:53988/WebService1.asmx"
/></wsdl:port>

<wsdl:portname="WebService1HttpPost"binding="tns:WebService1Ht
tpPost"><http:addresslocation="http://localhost:53988/WebService
1.asmx" />

</wsdl:port></wsdl:service>

</wsdl:definitions>

 

/*  here is the server */namespace WSTest

{

///<summary>

/// Summary description for WebService1

///</summary>[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)][ToolboxItem(false)]

// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line. 

// [System.Web.Script.Services.ScriptService]

publicclassWebService1 : System.Web.Services.WebService

{[WebMethod]publicUserMessage HelloWorld2(string clientmessage)

{

UserMessage result = newUserMessage();result.Message1 = "hello" +
clientmessage;

result.Message2 = "there";return result;

}

}

}

/* here is the client */

using WSTest; //shared definition of UserMessage found here.

 publicpartialclass_Default : System.Web.UI.Page

{protectedvoid Page_Load(object sender, EventArgs e)

{localhost.WebService1 proxy = new localhost.WebService1();

//UserMessage umsg = (UserMessage)proxy.HelloWorld2("I am the
client"); // this cast not allowed.UserMessage umsg =
proxy.HelloWorld2("I am the client"); 

// compile Error: Cannot implicity convert type 'localhost.UserMessage' to
'WSTest.UserMessage'

}

}

 

/* and the shared class */namespace WSTest

{

publicclassUserMessage

{publicstring Message1 { get; set; }publicstring Message2 { get; set; }

}

}
Post Reply
Re: Simple web service with User Object parameter
Thu, 3 Apr 2008 15:26:11 +0000
The wsdl looks okay, but there's your problem:
// compile Error: Cannot implicity convert type 'localhost.UserMessage' to
'WSTest.UserMessage'


 
You're trying to implicitly cast to the UserMessage type from your library on
the client side.

I don't think that will work. You need to receive the response into the proxy
type generated from the wsdl, i.e. localhost.UserMessage not the one in
namespace Test.

 Hope that helps.
Post Reply
Re: Simple web service with User Object parameter
Thu, 3 Apr 2008 15:54:54 +0000
Can you paste the generated WSDL?
Post Reply
Re: Simple web service with User Object parameter
Thu, 3 Apr 2008 19:35:11 +0000
Ok, that makes sense... thank you .... But what about the behaviors on
WSTest.UserMessage ... I have a reference to this on the client.  There must be
way to get a WSTest.UserMessage from a localhost.UserMessage  ???  -- but it
doesn't appear to be through casting (implicit or otherwise).

thanks in advance.
Post Reply
about | contact