public class ServiceFactory
{
private static ServiceFactory instance;
public static ServiceFactory Instance
{
get
{
if (instance == null)
{
instance = new ServiceFactory();
}
return instance;
}
}
private string serviceUrl;
public string ServiceUrl
{
get { return serviceUrl; }
set { serviceUrl = value; }
}
public void SetServiceUrl(string rootUrl, string svrUrl)
{
string t_url = "";
if (!string.IsNullOrEmpty(svrUrl) && !string.IsNullOrEmpty(rootUrl))
{
while (rootUrl.EndsWith("/") || rootUrl.EndsWith("\\"))
{
rootUrl = rootUrl.Remove(rootUrl.Length - 1, 1);
}
if (svrUrl.StartsWith("~"))
{
t_url = svrUrl.Replace("~", rootUrl);
}
else
{
t_url = svrUrl;
}
}
this.serviceUrl = t_url;
}
public void SetSoapClientServiceUrl(object client)
{
if (!string.IsNullOrEmpty(serviceUrl))
{
var endpoint = client.GetType().GetProperty("Endpoint").GetValue(client, null);
endpoint.GetType().GetProperty("Address").SetValue(endpoint, new System.ServiceModel.EndpointAddress(serviceUrl), null);
}
}
}
<script runat="server">
protected string rootUrl;
protected void Page_Load(object sender, EventArgs e)
{
string str = "http://" + Request.Url.Host + ":" + Request.Url.Port + Request.ApplicationPath;
while (str.EndsWith("/"))
{
str = str.Remove(str.Length - 1);
}
this.rootUrl = str;
}
</script>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
<param name="source" value="<%=this.rootUrl %>/ClientBin/AdmUserMgr.xap" />
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<param name="InitParams" value="rootUrl=<%=this.rootUrl %>,svrUrl=~/WebServices/AdmUserMgr.asmx" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration: none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
style="border-style: none" />
</a>
</object>