Tuesday, April 1, 2008

Dynamic Web Reference problem.

Hello guys!

I've encountered a problem 2 days ago and till now I don't know how to handle it.
Well the problem is that I have 2 app.configs (one in a class library DAL, another one in Windows Forms UI), so in DAL I've added a Web Reference and changed it's property "URL Behaviour" to Dynamic. So in DAL app.config automatic were added following lines
[code]

[/code]
And automatic was generated a Reference.cs class which made a constructor and overloaded WS methods.

Now when I copy this setting section into UI app.config then it's supposed to be dynamic, this means that I can change the URL setting in UI app.config, and our proxy class (Reference.cs) will also be rebuild for inputted URL.
But it doesn't make this. When I change in UI app.config URL value it changes the ws.Url property to that value but the responce is null.

public WSAgencesAccessor()
{
ws = new P5_PLA.DAL.WsPLA.WsPLA();
// when we put here breakpoint we'll see what ws.Url is equal to value inputted in UI app.config
}
#endregion

#region Get
public AgencesDataSet.T_AgencesDataTable GetAgences()
{
string responce = ws.WsPLAGetAllAgences001(DataUtils.SessionId, Properties.Settings.Default.SRC, DataUtils.SessionIp);
// here responce is equal to null
AgencesDataSet ds = new AgencesDataSet();
new DataUtils().ManageXMLResponceGet(responce, ds);
// after execution of ManageXMLResponceGet I receive a ArgumentNullException
// because of the responce argument
return ds.T_Agences;
}

After examining WS url I know that it works perfectly (tested them in WSDL from Eclipse). Now the Reference.cs looks like this
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.1433")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="WsPLAHttpBinding", Namespace="http://localhost:8080/WsPLA/services/WsPLA")]
public partial class WsPLA : System.Web.Services.Protocols.SoapHttpClientProtocol {

private System.Threading.SendOrPostCallback WsPLAGetUsers001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAGetAllProjets001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAAjoutPlanif001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLADeletePlanif001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAAjoutProjet001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAGetProjetById001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAGetPlanifs001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAGetAllAgences001OperationCompleted;

private System.Threading.SendOrPostCallback WsPLAGetAgenceById001OperationCompleted;

private bool useDefaultCredentialsSetExplicitly;

///
public WsPLA() {
this.Url = global::P5_PLA.DAL.Properties.Settings.Default.P5_PLA_DAL_WsPLA_WsPLA;
if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
this.UseDefaultCredentials = true;
this.useDefaultCredentialsSetExplicitly = false;
}
else {
this.useDefaultCredentialsSetExplicitly = true;
}
}

public new string Url {
get {
return base.Url;
}
set {
if ((((this.IsLocalFileSystemWebService(base.Url) == true)
&& (this.useDefaultCredentialsSetExplicitly == false))
&& (this.IsLocalFileSystemWebService(value) == false))) {
base.UseDefaultCredentials = false;
}
base.Url = value;
}
}

public new bool UseDefaultCredentials {
get {
return base.UseDefaultCredentials;
}
set {
base.UseDefaultCredentials = value;
this.useDefaultCredentialsSetExplicitly = true;
}
}

///
public event WsPLAGetUsers001CompletedEventHandler WsPLAGetUsers001Completed;

///
public event WsPLAGetAllProjets001CompletedEventHandler WsPLAGetAllProjets001Completed;

///
public event WsPLAAjoutPlanif001CompletedEventHandler WsPLAAjoutPlanif001Completed;

///
public event WsPLADeletePlanif001CompletedEventHandler WsPLADeletePlanif001Completed;

///
public event WsPLAAjoutProjet001CompletedEventHandler WsPLAAjoutProjet001Completed;

///
public event WsPLAGetProjetById001CompletedEventHandler WsPLAGetProjetById001Completed;

///
public event WsPLAGetPlanifs001CompletedEventHandler WsPLAGetPlanifs001Completed;

///
public event WsPLAGetAllAgences001CompletedEventHandler WsPLAGetAllAgences001Completed;

///
public event WsPLAGetAgenceById001CompletedEventHandler WsPLAGetAgenceById001Completed;

///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://localhost:8080/WsPLA/services/WsPLA", ResponseNamespace="http://localhost:8080/WsPLA/services/WsPLA", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("out", IsNullable=true)]
public string WsPLAGetUsers001([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string in0, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string in1, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string in2, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string in3) {
object[] results = this.Invoke("WsPLAGetUsers001", new object[] {
in0,
in1,
in2,
in3});
return ((string)(results[0]));
}

When I change the values of RequestNamespace, ResponceNamespace and Namespace to URL i need everything works fine. So the URL from UI app.config and from Reference.cs should be the same to work. Now how can I change this all thing to a really dynamic behaviour, just changing URL in app.config UI?

No comments: