0

I want access to the Methods of my WebService (SOAP).. I tried it on a other way, but didnt worked.. Now I will create this scenario in Javascript:

MyWebService client = new MyWebService();

So that I can access the Methods like:

client.GetYear()

in javascript!

Hope u guys can help me..

EDITED:

If you create a WebService, u can access it like:

MyWebService client = new MyWebService();

with:

string theName = client.GetName();

so but I want to acces this method with javascript, not with C#, How do I create the "client" in Javascript?

4
  • your question does not help us understand the problem. If you can give more information about what you are trying to do, people here will be more than happy to help Commented Aug 5, 2011 at 14:42
  • Calling a SOAP service in JavaScript is not like creating an object and then calling a method. See codeproject.com/KB/ajax/JavaScriptSOAPClient.aspx for more details. Commented Aug 5, 2011 at 14:46
  • I edited now, hope its more understandable.. Commented Aug 5, 2011 at 14:46
  • @Teja.. I know .. I tried another ways, nothing worked.. I just get it worked if the Services was from Visual Studio created, so ends with .svc or .asmx .. but mine I wasnt able to access.. So I try another way Commented Aug 5, 2011 at 14:50

1 Answer 1

1

If I understand you correctly and you are asking on how to create a class and instantiate it within JavaScript, then you should know that by default such things are not a part of JavaScript.

You can have objects, but classes are different issue. There are some walkthroughs however. One of them is here: http://www.phpied.com/3-ways-to-define-a-javascript-class/

So, basically you can do something like that (see this jsfiddle for proof):

var MyWebService = function(){
    this.message = 'some message';
    this.showMsg = function(){
        alert(this.message);
    }
    return this;
}

var service = new MyWebService();
service.showMsg();

That way you can mimic the way classes work - you create functions that have methods.

Is this what you wanted?

Sign up to request clarification or add additional context in comments.

3 Comments

I think @eMi is talking about invoking a SOAP service from JS, not creating a custom JS object and invoking it..
yes it goes in this way.. but the problem is, that I want create the Methods manually.. they exists in the Webservice.. I just want to access them, with a "in javascript" created Variable -client- of type MyWebService..
@eMi: I can not help with using SOAP from JavaScript (although I think it is possible). But you can create methods the way you create other properties of the object. So, if in one of the methods you determine the methodName, you can create a function in the following manner: this[methodName] = function(){ /* do what you need here */ }.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.