Showing posts with label WebServices. Show all posts
Showing posts with label WebServices. Show all posts

Wednesday, 23 July 2008

Change default Port for the ASP.NET Development Server

When you use the ASP.NET Development Server to run a file-system Web site, by default, the Web server is invoked on a randomly selected port for localhost. For example, if you are testing a page called Default.aspx, when you run the page on the ASP.NET Development Server, the URL of the page might be the following:

http://localhost:3499/Default.aspx

To specify a port for the ASP.NET Development Server
  1. In Solution Explorer, click the name of the application.

  2. In the Properties pane, click the down-arrow beside Use dynamic ports and select False from the dropdown list.

    This will enable editing of the Port number property.

  3. In the Properties pane, click the text box beside Port number and type in a port number.

  4. Click outside of the Properties pane. This saves the property settings.

    Each time you run a file-system Web site within Visual Web Developer, the ASP.NET Development Server will listen on the specified port.

Please note the above steps are based on WebSite/ WebServices project. For the Web Application project, we can fix the port number by following steps:

1.  Right click the Project in the Solution Explorer, and then select “Properties”
2.  Click “Web” tab.
3.  Check “Specific port” instead of “Auto-assign Port”.

If you want to debug with IIS, please follow the first and second steps above, and then check “Use IIS Web Server” instead of “Use Visual Studio Development Server”. Also, click the “Create Virtual Directory” button.

Note:

Visual Web Developer cannot guarantee that the port you specify will be available when you run your file-system Web site. If the port is in use when you run a page, Visual Web Developer displays an error message.

Share:

Friday, 18 July 2008

Method Overloading in WebServices

 

Web services are also classes just like any other .NET classes. Nevertheless they have methods marked as WebMethods that can be exposed by the WebServices to be consumed by the outside world. Apart from these WebMethods they can also have normal methods like any other classes have.


Since a web service is a class it can utilize all the OO features like method overloading. However to use this feature on WebMethods we need to do something more that is explained in this article.

Creating WebMethods:


Let us create a simple WebService that has the following overloaded methods:
public int AddNumbers(int a, int b)

public int AddNumbers(int a, int b, int c)

public decimal AddNumbers(decimal a, decimal b)

All these three methods return variants of a Added numbers to the WebClient. Let us now mark the methods as Web Methods. To acheive this apply the [WebMethod] attribute to the public methods.

[WebMethod]

public int AddNumbers(int a, int b)

    return a+b;

}

[WebMethod]

public int AddNumbers(int a, int b, int c)

    return a+b+c;

}

[WebMethod]

public decimal AddNumbers(decimal a, decimal b)

{

    return a+b;

}

This would compile fine. Run the WebService in the browser. That should give an error saying that the AddNumbers() methods use the same message name 'AddNumbers' and asking to use the MessageName property of the WebMethod.

Adding the MessageName property:

Add the MessageName property to the WebMethod attribute as shown below:

[WebMethod]

public int AddNumbers(int a, int b)

    return "a+b";

}

[WebMethod (MessageName="AddThreeNumbers")]

public int AddNumbers(int a, int b, int c)

    return a + b + c;

}

[WebMethod (MessageName="AddDecimal")]

public decimal AddNumbers(decimal a, decimal b)

{

    return a+b;

}

Now compile the WebService and run in the browser. You can see that the first method is displayed as AddNumbers wherein for the second and third method the alias we set using the MessageName property is displayed.

Share:

Sunday, 30 March 2008

Programming Webservices using WSDL (Without WebReference)


WSDL stands for Web Service Description Language, a standard by which a web service can tell clients what messages it accepts and
which results it will return. WSDL contains every details regarding using web service


  1. Method and Properties provided by web service

  2. URLs from which those method can be accessed.

  3. Data Types used.

  4. Communication Protocol used.


This post will help you to program with WSDL without using webservice reference. In brief following are the steps you need to take.


Create the proxy class using the tool WSDL.exe* (this can be accessed using Visual Studio.NET command prompt).


Following is the syntax of the wsdl.exe command you can use to generate the proxy class.

wsdl.exe  <options><url><url>...



for e.g: wsdl myservice.wsdl -language:cs


Based on the schema of myservice.wsdl this Utility will generate the proxy class myservice.cs in c# in the current directory.
You can use lots of other options also, you can find the options by using the command wsdl /? in command prompt.


If you want, you can also generate the VB class file by using the command
wsdl myservice.wsdl -language:vb


You can create a project or use the existing project now and add the class in your project,
thats it :) now you are ready to create the instance of the class, call methods, etc.



I hope this is helpful, if you need more detail please leave a comment, I will try to answer.


Also if you are very new to webservice you can browse this site,

I found this very helpful for beginners :
All About Web Service in .Net


And some of the good sites which can give you more indepth knowledge.


Creating and Consuming .NET Web Services in Five Easy Steps


Creating a .NET Web Service - By Chris Peiris


Programming .NET Web Services -O'Reilly




*WSDL.exe is the utility to generate code for xml web service clients and xml webservices using ASP.NET from WSDL contract files,
XSD schemas and .discomap discovery documents. This tool can be used in conjunction with disco.exe.
Share: