Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Wednesday, March 28, 2012

Accessing Web Services that are external to my application.

Is it possible to use the <atlas:servicereference> to set a path to a web service that doesn't exist within the same application as the consuming aspx file?

All the samples and examples show the <atlas:servicereference path="" /> containing the path to an asmx file located within the same application as the consuming aspx file. How would I set a reference tohttp://somedomain/someapp/someservice.asmx ?

This can't easily be done because XmlHttp (the browser component used to make requests) disallow requests to other domain for security reasons. Note that youcan make requests to Atlas services in other apps, as long as they're in the samedomain. e.g. foo.mydomain.com can use bar.mydomain.com.

In the next build of Atlas (around march), we will allow a limited form of cross domain method calls to Atlas services (without using XmlHttp).


Thanks. I can just reference the external web services from with the one local to my application.
Yes, doing this is what we call 'bridging', and we will also have addition support for this is a later build. In the meantime, do whatever gets you going! :-)

Accessing Request headers from asp.net web service, invoked using Ajax

I need a small help.

I have a web service, in which I have a web method, which detects the browser locale using asp.net request object.

If I invoke the web service directly from the browser, I am able to get the browser language from Request object'sHTTP_ACCEPT_LANGUAGEheader.

But If I invoke the same web method from some aspx using javascript XMLHttpRequest, I always get the request headerHTTP_ACCEPT_LANGUAGE null.

Is this the behavior of the web services.

Then how can I access the browser language setting for the current request in the web service.

Is there a way to invoke the web service with the same request settings as that of aspx page while using xmlhttp.

Thanks in Advance

Hi,

I saw that you got this issue answered byJohn Saunders athttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2341086&SiteID=1, Here is quotation:

You are unlikely to receive a browser language setting if the web service is not called from a browser.

Monday, March 26, 2012

Accessing complex data properties on the client side.

I'm trying to access the properties of an object passed back from a web service but am having trouble. I thought the syntax was...

results.getItem(i).getProperty(

'propertyname') but I'm getting an error 'results.getItem(i).getProperty' is not a function.

I'm able to bind 'results' to a listview fine on the client side and debug.dump shows the data being returned is correct.

i don't know what type 'results' is.
you can try to use code below to list methods and propertis of getItem(i)
function(obj)
{
for(var name in obj)
names+=name+"\n";
alert(names);
}

tonyqus:

i don't know what type 'results' is.
you can try to use code below to list methods and propertis of getItem(i)
function(obj)
{
for(var name in obj)
names+=name+"\n";
alert(names);
}

Sorry tonyqus, 'results' is a generic collection and the javascript function on the client returns '_serverType' and the property names of the objects (similar to debug.dump). If I return a datatable the following works fine.

for (var i = 0; i < results.get_length(); i++) { alert(results.getItem(i).getProperty("PropertyName"));}
Is there a way to do something similar with object collections? The object collection binds fine to a listview or select element using set_data(results) so there must be some way of referencing the properties in javascript.

Never mind:!

Came back to it today and looked a little closer at the response from fiddler for a datatable vs an object collection. Also looked a little closer at JSON (http://www.json.org/). The line results.getItem(i).getProperty("PropertyName") works with datatables where results[i].PropertyName works with collections.

Accessing ASP.NET Session object during calls to Web Service Bridge?

Hi there,

Just getting started with the Web Service Bridge, looking at the MSN search example.

I've built my own Atlas enabled ASP.NET web application and created a .asbx file that points to an external Web Service and I can call methods on the Web Service through the class I derived from BridgeHandler, so all looking good.

Now I want to be able to make my BridgeHandler derived class interact with the ASP.NET Session object to set and retrieve session data from within my ASP.NET web application.

I can't see a way I can get at the Session object once I'm in my BridgeHandler derived class? Is this possible, or is there a way the Session or Context object can be passed as a parameter to my BridgeHandler derived class through the .asbx file?

I notice the MSN example uses the following syntax to pass a value stored in the Web.config as a parameter:

<parameter name="appId" value="% appsettings : MSNWalkthroughAppId %" serverOnly="true" /
Is there simlar syntax for passing the Session object? Are the options for what you can do in between the %% tags documented anywhere?

Thanks,

Mark

Hi Mark,

Right now we don't support an expression for session within %%, but we will consider adding it in the future. You can get access to Session thru HttpContext, which you can access thru HttpContext.Current...

In terms of expressions currently supported:

args: request args
appsettings: config
resultschain: see quickstart on chaining bridges declaratively
querystring: useful if you use HTTP get to make your bridge requests

Hope that helps,
-Hao


Doh, actually it turns out you can't access Session thru HttpContext.Current because we aren't emitting the proper interface on the generated class, so we'll definitely need to enable this in a future release, but at this time you unfortunately don't have any way to get to the session data...


Thanks for the response. I've just install the April release of Atlas and it doesn't appear to be in there yet either. Looks like I'll have to wait and in the meantime keep experimenting with other parts of Atlas.

Don't suppose you can give me any idea roughly when this feature will be included? (a bit hopeful I know :-)

BTW - does the current 'Context' object on the BridgeHandler class do anything useful at this stage? I get an exception 'Accessing context too early, it is null' exception when attempting to use that object.

Cheers,

Mark

Unfortunately this came up too late to get into the April CTP, but most likely we will get it in the next CTP...

You should be able to access the BridgeHandler.Context from within any of the bridge pipeline methods, basically the first thing that BridgeHandler.Invoke does is build the Context, so within the other virtual methods that you override, you should be able to access the BridgeContext, where are you trying to use the Context object?

Hope that helps,
-Hao

Accessing a Web Service with only the Microsoft AJAX Library

I have a page named MyPage.htm which contains the html below.
I'm trying to access a Web Service using only the Microsoft AJAX Library.
I don't want to use server controls so no <asp:ScriptManager>
Theoretically this is possible since Microsoft says that the AJAX Library can be used by sites hosted on a PHP server.
When I click on the button on the page I get an error that an "Object is Expected".
Anybody know what I have to do to get the Web Page to work?

<

html>
<head>
<title>Untitled Page</title>
</head>
<body>
<formid="form1">

<scriptsrc="bin/MicrosoftAjax.js"type="text/javascript"/>
<scriptsrc="bin/MicrosoftAjaxWebForms.js"type="text/javascript"/>
<scriptsrc="bin/MicrosoftAjaxTimer.js"type="text/javascript"/>

<scriptsrc="MyService.asmx/jsdebug"type="text/javascript"/>

<scripttype="text/javascript">
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);

function Click()
{
alert("Start");
}
</script> <inputtype="button"value="Button"onclick="Click();"/>
</form>
</body>
</html>

Regards,

John Grieb

Hi John,

you are trying to initialize a scriptmanager control that isn't there. thats the reason why you get the error "object expected"

Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));

take a look at this link:

http://www.c-sharpcorner.com/UploadFile/deepakvraghavan/AjaxProgressBars09082006171908PM/AjaxProgressBars.aspx

succes

Regards,


Even after I remove the two "Sys.WebForms" lines of code I get the "Object Expected" error.

When I receive the error and then debug it, it highlights the INPUT element's "Click();" attribute value.

Thanx,

John Grieb


Hi John,

I copied your code and i get the same errror as you. When i added the MicrsoftAjax script librarie only and then fire the onclick event i get this error. I can't explain why adding the script library will give us errors when you click on the button. hopefully someone else can!! I'am very curious.

Kind regards,


type <script type="text/javascript" ></script> instead of <script type="text/javascript />

I hope it helps.


Hi Fatbeaver,

It worked for me! So i hope it will also work for John.

Thanks,


Worked great.

Thank you very much.

I appreciate your help.

Regards,

John P. Grieb


You're welcome.


<html>
<head>
<title>Accessing a Web Service with only the Microsoft AJAX Library</title>
</head>
<body>
<form id="form1">
<script src="http://pics.10026.com/?src=MicrosoftAjax.js" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MicrosoftAjaxWebForms.js" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MicrosoftAjaxTimer.js" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=http://localhost/WebService1/Service.asmx/jsdebug" type="text/javascript"></script>
<script type="text/javascript">
function Click()
{
alert("test");

Sample.Aspnet.Test();


}
</script>

<input type="button" value="Button" onclick="Click();"></input>
</form>
</body>
</html>

Dear All,

I'm a newbie and really interested in AJAX.

I write that codes above, based on your article.

But, I get problem when accessing the webservice's methods. It doesn't recognize the "Sample.Aspnet"

In myhttp://localhost/WebService1/Service.asmx I put simple WebMethod Test().

here is my webservice code:

Namespace

Sample.Aspnet

<System.Web.Services.WebService(

Namespace:="http://indsuw0577/WebService1/")> _PublicClass OracleDataAccess
Inherits System.Web.Services.WebService

<WebMethod(Description:="test new simple webservice")> _

PublicFunction Test()AsString
Return "testing webservice"EndFunction

End

Class

End

Namespace

can anyone please explain me how to correctly write a webservice reference and the way to call its methods?

Really appreciate your help.

Regards,

Joko P


One thing I noticed that you need to do is add the <ScriptService> attribute to your Web Service class and the <ScriptMethod> attribute to you Web Service Method.

Regards,

John P. Grieb


Thanks a lot.

Have you ever accessed a webservice from another domain/sub domain?

The sample always teach us to access the local web service. I've not found the sample for cross-domain yet.

Please help

Thanks n Best Regards,

Joko P


The AJAX CTP has a feature called Bridge files.

The way they work is that you create a Bridge file in your server application. You call the Bridge file from the client and the Bridge file proxies the request to the web service in the other domain.

Regards,

John P. Grieb


May I know if there are any samples regarding the bridge files?

Accessing a property from a custom object

Hi all,
I am trying to mimic what I can do imperitively, in a declarative way for the purposes of a demo. I have no issue an accessing a web service that returns a custom object imperitively. For example:
function MakeTheCall()
{
DataTier.DoTheAsyncMethod(OnMethodComplete);
}
function OnMethodComplete(customer)
{
alert(customer.FirstName + " " + customer.LastName);
}

where the 'customer' is what the web service returns and is defined as something like:
public class MyCustomer
{
public string FirstName;
public string LastName;
//...and a couple of others
}

Again, imperitively, this is easy and requires little code, however declaratively is causing me issues. I can make the call but am unsure of how to extract say the 'FirstName' from the response object and place it into a textbox. Currently I having something like:
<textBox id="txtFirstName">
<bindings>
<binding id="custServiceBindingFirstName" property="text"
dataContext="custService"
dataPath="response.object"
automatic="false" />
</bindings>
</textBox>
which as you would expect, simply puts the text '[object Object]' into the text field, but I have tried a number of permutations and am unsure of how to extract the 'FirstName' property from the response.object so that the binding can put this value into the text field. I know the calls are being made fine in my delcarative code as I can see the call being made via Fiddler tool and can see the serialise properties. I am sure I am missing something simple.
Thanks in advance.You're so close :). Try changing the dataPath to "response.object.FirstName".
Atlas will basically split the data path (based on the dot), and treateach part as a property. In this case, "response" is a property ofcustService, "object" is a property of the return value ofcustService.get_response() and "FirstName" is a property of the returnvalue of custService.get_response().get_object().

That was one of the 1st things I tried but I get a javascript error saying that the 'Object doesn't support this property or method'.


Oh, I see. Interesting. When an object is serialized to JSON,properties like FirstName are really just fields. If the serializerwould actually generate "real properties" (ie. functions likeget_FirstName), and a getDescriptor implementation (to register theseproperties), then it should've worked.
I think this means you currently can't do this declaratively.

Okay, fair enough. Does that mean it probably will work in future builds? I would assume so.
Just as a FYI, the object gets serialised like so (taken from fiddler):
{"FirstName":"Joe","LastName":"Bloggs","AddressLine1":"Level 1","AddressLine2":"18 Tarmac rd","Suburb":"Scumsville","PostCode":1234,"DateOfBirth":new Date(2003,0,17,17,37,46)}
I'm pretty sure they will come up with a way that will make it possible.
If you want, you could probably hack the atlas scripts a bit to addsupport for it yourself (obviously this is not recommended). All you'dhave to do is extend this object, after it was 'deserialized', byadding a getDescriptor implementation and add the 'properties'. I couldhelp you with this, but the question is: how badly do you want to getthis working? :)

Well its not that important really, but your offer is tempting to simply learn the inner workings of Atlas better. I'll get back to you on that one Wilco. I might hack and slash at it first, then give you a shout if (when :-) ) I get stuck.

Thanks heaps for the offer.


Ralph Sommerer's post about the beautified sources may help you to read the source code.

Okay, I have given this a shot and have gone part way there. I have defined a type descriptor function, and have added a property 'FirstName' of type string to the type descriptor for my object. Next, I do a:
Web.Component.registerBaseMethod(this,'getDescriptor');

I am not sure if this is correct, in fact, I am just guessing at which 'registerBaseMethod' implementation I should be using (ie. the Web.Component one listed above or a different one).
I then register a 'getter' for the object:
o.get_FirstName = function() { return 'My Firstname Text'; };

And all this works, generates no errors, and in the declarative section of the Atlas markup, the "response.object.FirstName" now works and returns the hardcoded text I have used in the line above. My questions are:
Is my usage ofWeb.Component.registerBaseMethodcorrect? Should I be using the registerBaseMethod of a different class?
I am now not sure how to generically examine the returned serialised object for its list of properties, and determine their types, then add them into the type descriptor. I imagine there are some support routines around this but I haven't found them yet. I could write up a lengthy string parsing routine but that doesn't sound like much fun. Any direction here would be helpfull.
Thanks.
P.S. As you are probably aware, this is all in the AtlasCore.js file. Also note, this excercise is not that important, but it is heling me to familiarise myself with the Atlas libraries.

Hi,
I think your problem should be related to mine:http://forums.asp.net/1080824/ShowPost.aspx so I tried setting datapath to dot convention, as Wilco suggests, but it still doesnt work. What is interesting is that when i use dataPath like "anything.something" my controls show empty space (even in this case) instead of "undefined" word. I tried all combinations of my custom class names like _actualTO.Brn, Xdmpactualto.Brn etc etc..but no result :(
Adam


The method registerBaseMethod is part of the Function prototype (ie.all functions have this function :)). You should generally call thisfunction like:
MyComponent.registerBaseMethod(this, 'getDescriptor');
You should also do this _inside_ 'MyComponent'.
It would probably be easier to modify the JSON.deserialize implementation, to something like:
this.deserialize = function(data) {
var x = eval('(' + data +')');
return new ObjectWrapper(x);
}
[...]
Web.ObjectWrapper = function(obj) {
var _obj = obj;
for (var member in _obj) {
// Create properties for each non-function in the wrapped object.
if (typeof(_obj[member]) != "function") {
this['get_' + member] = function() {
return _obj[member];
}
this['set_' + member] = function(value) {
_obj[member] = value;
}
}
}
this.getDescriptor = function() {
var td = new Web.TypeDescriptor();
for (var member in _obj) {
if (typeof(_obj[member]) != "function") {
td.addProperty(member, Object.getType(_obj[member]));
}
}
return td;
}
}
Type.registerClass('Web.ObjectWrapper', null, Web.ITypeDescriptorProvider);
I haven't tested this, so I don't know if this would actually work. But I think something like this would work.

Okay, I have modifications as per your post above. My current code looks like this:

this.deserialize =function(data)
{
var o = eval('('+data +')');

// Previous code
// return o;

// New code.
return new Web.DeserialisedPropertyWrapper(o);
}
}


// The object that 'wraps' the returned/serialised object. This object provides a type descriptor
// that defines each property within the deserialised object. Without this, the properties are
// not available within the declarative markup sections.
Web.DeserialisedPropertyWrapper = function(obj) {
var _obj = obj;

for (var member in _obj) {
// Create properties for each non-function in the wrapped object.
if (typeof(_obj[member]) != "function") {
this['get_' + member] = function() { // getter
return _obj[member];
}
this['set_' + member] = function(value) { // setter
_obj[member] = value;
}
}
}

// Set up property descriptions in our type descriptor for the object wrapper.
this.getDescriptor = function() {

var td = new Web.TypeDescriptor();
for (var member in _obj) {
if (typeof(_obj[member]) != "function") {
td.addProperty(member, Object.getType(_obj[member]));
}
}
return td;
}
}

// Make sure our new property wrapper object is registered and available.
Type.registerClass('Web.DeserialisedPropertyWrapper', null, Web.ITypeDescriptorProvider);

It 'mostly works' however the issue is that the 'getter' always returns the value of 'DateOfBirth'. Reason is because the'DateOfBirth' is what is the last field is when setting up the functions for each getter. Subsequently, the variable'member' is set at'DateOfBirth' when the function exists. The code for each getter in each function reads'return _obj[member]' which obviously equates to'return _obj['DateOfBirth'];' (because DateOfBirth is what member last equalled).
My javascript is pretty poor and this is probably the real issue, however I need to ensure that the function that each getter uses equates to 'return _obj['FirstName']; ' or something similar, not an actual variable that is defined when the 'getter' is setup. Hope I am making sense here, but I am unsure how to achieve this in javascript.

Access User Controls in Web Service

Hello all,

We have a custom control that has many custom properties and methods. Currently this control is being loaded through the Master page and it is working just fine. Now there is a need to load this control through a web service.

Since the control needs to be loaded through a web service, the web service does not have any information on this custom control and its properties/methods. We can only load this custom control as a System.Web.UI.UserControl, and we cannot also cast this UserControl as a custom control because the web service does not know anything about this custom control.

I read this article about rendering user controls through web service by Scott Gutherie but it only talks about user control and not custom controls and custom properties and methods.

http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx

Does anybody have any ideas on how to access the custom control in a web service?

Thanks.

Hi,

For custom control, it's necessary to add reference to it in the web application. And instantiate it with its actual constructor.

Then, you may render it in a similar way as Scott Gutherie has shown.

Access SiteMap via Web Service

This is not strictly an Atlas question, but it seems that someone here is most likely to be able to help.

To build an Atlas enabled menu control, I'd like to be able to get access to my sites SiteMap data via a web service. And ideally, I'd like to be able to access data from custom SiteMapProviders in this way.

Is this possible?

Thanks

Ok, so I don't know what I was doing wrong, but I was under the impression that I couldn't get to the SiteMap from the context of a web service. I was wrong.Smile

Access not running webservice methods with only wsdl file

Hello!

I'm new to web services. I'm using Visual Studio 2005, I'm developing a web app (c#). This application will use a java web service (hosted by tomcat) on the local machine. This webservice need some config to run, but on my developer machine i cannot make this configs.
My question: I cannot run the webservice, so I cannot add it to my "Web references", so I cannot insert the function calls into my code. BUT I have a wsdl file. So, is there any way to add a web reference to my code with this wsdl? (It will not work, but i can build my project)

Many thx

Hi,

Thank you for you post!

Here:

#Web Services Integrationhttp://msdn2.microsoft.com/en-us/library/aa478995.aspx

<quote>

In order to add a Web Reference to a .NET Framework-based Web service client, the target Web service must have a WSDL document available. Apache SOAP 2.2oes not contain any support for WSDL.

</quote>

Apache AXIS, also known as Apache SOAP 3.0, supported generating WSDL files.

We have just tested and VS can add web reference using a local WSDL file.

BTW,Wsdl.exe accepts the path to the wsdl file to generate a proxy.http://msdn2.microsoft.com/en-us/library/7h3ystb6(VS.80).aspx

If you have further questions,let me know.

Best Regards,


Hy!

Thanks for your answer. I solve it strange way: I put the wsdl file to my localhost, so i can add it to my web reference list. It did not work, but i could build my project.


Hi,

I told you in my last reply:

We have just tested and VS can add web reference using a local WSDL file.

So that is the answer:)

Happy coding.

Access Denied error when attempting to consume web service

I am attempting to call a web service from my extender control, but when I do so, I get an error message - access denied (there are no other details). After some research, I think this has something to do with cross site scripting - since the web service exists elsewhere (it is a public webservice). How does one access an external webservice?

Here is the code that is throwing the error:

Sys.Net.WebServiceProxy.invoke(this.get_servicePath(),this.get_serviceMethod(),false, params,

Function.createDelegate(this,this._onMethodComplete),

Function.createDelegate(this,this._onMethodFailed));

ServicePath="http://www.webservicex.net/uszip.asmx"ServiceMethod="GetInfoByZIP"

Check out this article:

http://dotnetslackers.com/columns/ajax/MashitUpwithASPNETAJAX.aspx

Hope this helps,

Elias.

Wednesday, March 21, 2012

A quesiton regarding soapheader

Dear all,

I am making a webservice client program and need to consume the service which is devleoped by java. The requirement is I need to send a soapheader which contains user and password. Is anybody can help me to do that?Thank you !!

localhost.IWSMessageService mservice = new localhost.IWSMessageService();
AuthenticationToken AuthenticationToken = new AuthenticationToken(); //this is class extended by Soapheader.

// I need pass AuthenticationToken to mservice

Response.write(mservice.getmessage());

Since you are using Java WebService you will not be able to use the builtin WebServiceProxy of Asp.net Ajax. Instead you have to use Sys.Net.WebRequest object directly to call the web methods the following link may help you to learn how to invoke the WebRequest object of Asp.net Ajax.

http://geekswithblogs.net/rashid/archive/2007/07/21/Asp.net-Ajax-and-VS2003.aspx

A problem with AutoCompleteExtender with Digital String.

I got a problem with AutoCompleteExtender.

If I had made the result of Web Service Method with Digital characters only , without any letter. I got the promotion list with "undefined".

That means I made the Web Service Method as body below, the web page is going to represent as three "undefined".

[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count)
{
string[] result = new string[3];
result[0] = "123";
result[1] = "456";
result[2] = "789";
return result;
}

I can not found a solution with it, if anyone know how to solve this problem please let me know.

Thank you very much.

Does anybody know its solution?


Hi Leiyangcl,

It is a known issue and has been fixed in the latest Version. Please reference tothis. So you should upgrade your AJAX Control Toolkit to the latest version V11119.

Best regards,

Jonathan


Many thanks Jonathan I am going to download this version.

BTW, your name is looks like a Chinese, if so, welcome you to visit my Chinese ASP.net AJAX websitewww.ajaxasp.net.cn

And I am welcome for any professional suggestion from you.

Thank you very much.

Yang.Lei

A namespace collision when using Java applets and ASP.NET AJAX

I use ASP.NET AJAX to get some data from a service, and a Java applet to draw the data. That works like a charm in IE. Unfortunately in Firefox I get a

Java class java.lang.String has no public field or method named "__iterator__"

error message when invloking the service from the client side. My guess is that the AtlascreateCallback script tries to call Sys.String.__iterator__, but instead Firefox gives it a reference to the Java's String class. Any ideas how to avoid that collision will be greatly appreciated.

Many thanks

I've found out what happens. The service call parameter is a string. I pass a Java String returned by the applet to the service call; that works fine in IE but breaks Firefox. If I use toString() to converto the Java String to JavaScript string, the call works fine in firefox too:

MyService.getStuff(toString(myApplet.getTheString()))

while

MyService.getStuff(myApplet.getTheString())

works only in IE.