Set the endpoint address before you add a WCF/Web Service in Silverlight

private EndpointAddress _endpointAddress;

 

public void GetMyData()

{

_endpointAddress = GacAppHelper.GetEndPointAddress("../ProtectedWebServices/PDAService.svc");

_myClientProxy = new MyService.MyServiceClient("CustomBinding_MyService", _endpointAddress);

//Call the Get Method

}

 

/// <summary>

        /// Get Endpoint address for the web service

        /// </summary>

        /// <param name="serviceRelativeUrl">Web Service Url</param>

        /// <returns>Endpoint address for the service url</returns>

        public static EndpointAddress GetEndPointAddress(string serviceRelativeUrl)

        {

            EndpointAddress endPointAddress = null;

 

            try

            {

                string completeUrl = Application.Current.Host.Source.AbsoluteUri;

                if (completeUrl.Contains("/"))

                    completeUrl = completeUrl.Substring(0, completeUrl.LastIndexOf('/') + 1);

                Uri requestUri = new Uri(completeUrl + serviceRelativeUrl);

                endPointAddress = new EndpointAddress(requestUri);

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

 

            return endPointAddress;

        }

Comments