user1045265
user1045265

Reputation: 55

calling web service

I created web service :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;

namespace MemberWebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.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]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public DataSet GetMemberData(string memberId, string thirdName)
        {
            SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Healthy;Integrated Security=TRUE");
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();

            da.SelectCommand = new SqlCommand("SELECT * FROM MemberMaster WHERE MemberId=@MemberId and ThirdName=@ThirdName", cn);
            da.SelectCommand.Parameters.Add("@MemberId", SqlDbType.NVarChar).Value = memberId;
            da.SelectCommand.Parameters.Add("@ThirdName", SqlDbType.NVarChar).Value = thirdName;

            ds.Clear();
            da.Fill(ds);
            return ds;
        }
    }
}

and when i run it this is the link :

http://localhost:19722/Service1.asmx

and it work OK.

if i call it in asp.net as a web reference it work correctly till the server port is open if i close the port the asp.net page cannot see the web service so how can i solve the problem and if i want to make this web service work on another device how can i do it ?

Upvotes: 0

Views: 147

Answers (1)

Joe Enos
Joe Enos

Reputation: 40431

That port is specifically used for Visual Studio - it's either Cassini or IIS Express, and is only used for debugging purposes, not for live production work. When you're ready to publish your service, it will likely go into IIS in a regular permanent port (probably 80). Once it's there, it will always be available for your client to call.

After you publish the service to IIS, you'll just need to update the config file for the client to point to the real permanent URL.

Upvotes: 2

Related Questions