PC Review


Reply
Thread Tools Rate Thread

Ajax invoke WebMethod with *out* Params

 
 
ckkwan@my-deja.com
Guest
Posts: n/a
 
      13th Mar 2008
[WebMethod]
public void Test(string Str)

for the WebMethod above, I am able to invoke using Ajax by:

WebService.asmx/Test?Str='something'

But in the case below:

[WebMethod]
public void Test(string Str, out string OutStr)

I tried to invoke using the similar string:

WebService.asmx/Test?Str='something'

But i failed. It seems like there is a need for me to assing the
OutStr, but again OutStr is not supose to to be set right?

So, how can I invoke the above WebMethod using Ajax?

Thanks in advance.
 
Reply With Quote
 
 
 
 
DSK Chakravarthy
Guest
Posts: n/a
 
      13th Mar 2008
The actual purpose of the OUT parameter is pass data as reference and let
the data be modified by the calling method. Isn't it?? as web service is
disconnected and invoked in a different context, you cann't pass any
reference from WebService.

Thus, you code shouldn't have the OUT parameter.

HTH
Chakravarthy


<(E-Mail Removed)> wrote in message
news:25f68760-500a-4ca5-81a0-(E-Mail Removed)...
> [WebMethod]
> public void Test(string Str)
>
> for the WebMethod above, I am able to invoke using Ajax by:
>
> WebService.asmx/Test?Str='something'
>
> But in the case below:
>
> [WebMethod]
> public void Test(string Str, out string OutStr)
>
> I tried to invoke using the similar string:
>
> WebService.asmx/Test?Str='something'
>
> But i failed. It seems like there is a need for me to assing the
> OutStr, but again OutStr is not supose to to be set right?
>
> So, how can I invoke the above WebMethod using Ajax?
>
> Thanks in advance.


 
Reply With Quote
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      13th Mar 2008
You cannot pass reference types over the wire from a webservice. Have the
method return a serializable type containing the two values instead.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net


"(E-Mail Removed)" wrote:

> [WebMethod]
> public void Test(string Str)
>
> for the WebMethod above, I am able to invoke using Ajax by:
>
> WebService.asmx/Test?Str='something'
>
> But in the case below:
>
> [WebMethod]
> public void Test(string Str, out string OutStr)
>
> I tried to invoke using the similar string:
>
> WebService.asmx/Test?Str='something'
>
> But i failed. It seems like there is a need for me to assing the
> OutStr, but again OutStr is not supose to to be set right?
>
> So, how can I invoke the above WebMethod using Ajax?
>
> Thanks in advance.
>

 
Reply With Quote
 
ckkwan@my-deja.com
Guest
Posts: n/a
 
      14th Mar 2008
On 3$B7n(B13$BF|(B, $B2<8a(B10$B;~(B56$BJ,(B, "DSK Chakravarthy" <dskch...@msn.com> wrote:
> The actual purpose of the OUT parameter is pass data as reference and let
> the data be modified by the calling method. Isn't it?? as web service is
> disconnected and invoked in a different context, you cann't pass any
> reference from WebService.
>
> Thus, you code shouldn't have the OUT parameter.
>
> HTH
> Chakravarthy


Well, if OUT parameter is NOT supose to appear in any WebService, then
Visual Studio should have generated a compile time error right

Besides, I look at the Input and Output XML string, it is 100%
possible if I invoke this WebService (with *OUT* parameter) using HTTP
SOAP or from anyother client like Java.

The problem now is, I need to invoke using Ajax, and passing in the
Query string as the Cmd


POST /WebConfig/Utils/External.asmx HTTP/1.1
Host: 127.0.0.1
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Test"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="http://tempuri.org/">
<Msg>string</Msg>
</Test>
</soap:Body>
</soap:Envelope>


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestResponse xmlns="http://tempuri.org/">
<Name>string</Name>
<Id>string</Id>
<Res>string</Res>
</TestResponse>
</soap:Body>
</soap:Envelope>
 
Reply With Quote
 
DSK Chakravarthy
Guest
Posts: n/a
 
      14th Mar 2008
Dude,

First thing first, as webservice is in a different box, you can't have the
reference of a variable leaked onto that box. Secondly, when the request
gets onto http, it disconnects the reference, thus leaving you with no
connection with the calling method for the caller. If you understand this,
you would never argue on the concept of using the OUT in a method of a
webserver.

Coming to the compiler identifying the flaw, pl understand that it is not a
syntax flaw, but a logical flaw. With in a web service you can have a method
exposing an OUT parameter to one more method. So, the compiler assumes that
you are defining that for the purpose of another method. Hope you got the
point.

If you are aware of the mechanism of invoking the webservice using HTTP SOAP
or any other possiblity, kindly share that with us.. Infact, it violates the
rule of isolation. Anyhow, if you are successful, in developing some code
like that, pl share that with us.

HTH

<(E-Mail Removed)> wrote in message
news:35c08815-d9b7-435a-8c72-(E-Mail Removed)...
> On 3$B7n(B13$BF|(B, $B2<8a(B10$B;~(B56$BJ,(B, "DSK Chakravarthy" <dskch...@msn.com> wrote:
>> The actual purpose of the OUT parameter is pass data as reference and let
>> the data be modified by the calling method. Isn't it?? as web service is
>> disconnected and invoked in a different context, you cann't pass any
>> reference from WebService.
>>
>> Thus, you code shouldn't have the OUT parameter.
>>
>> HTH
>> Chakravarthy

>
> Well, if OUT parameter is NOT supose to appear in any WebService, then
> Visual Studio should have generated a compile time error right
>
> Besides, I look at the Input and Output XML string, it is 100%
> possible if I invoke this WebService (with *OUT* parameter) using HTTP
> SOAP or from anyother client like Java.
>
> The problem now is, I need to invoke using Ajax, and passing in the
> Query string as the Cmd
>
>
> POST /WebConfig/Utils/External.asmx HTTP/1.1
> Host: 127.0.0.1
> Content-Type: text/xml; charset=utf-8
> Content-Length: length
> SOAPAction: "http://tempuri.org/Test"
>
> <?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
> schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <Test xmlns="http://tempuri.org/">
> <Msg>string</Msg>
> </Test>
> </soap:Body>
> </soap:Envelope>
>
>
> HTTP/1.1 200 OK
> Content-Type: text/xml; charset=utf-8
> Content-Length: length
>
> <?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://
> schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <TestResponse xmlns="http://tempuri.org/">
> <Name>string</Name>
> <Id>string</Id>
> <Res>string</Res>
> </TestResponse>
> </soap:Body>
> </soap:Envelope>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax, Webmethod, PageMethod (multiple versions) Rory Becker Microsoft ASP .NET 8 4th Aug 2008 02:58 AM
AJAX function (webmethod) call question dgk Microsoft ASP .NET 1 3rd Aug 2007 06:13 PM
BUG? How send params in WebMethod from PocketPC? Serg Microsoft Dot NET Compact Framework 0 21st Dec 2006 04:59 PM
BUG? How send params in WebMethod from PocketPC? Serg Microsoft Dot NET Compact Framework 0 21st Dec 2006 04:58 PM
Catch WebMethod name and params in Application_BeginRequest Franck Microsoft ASP .NET 1 4th Oct 2005 12:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 AM.