Please help…I’m going crazy….I have a wcf service that exists on a few different servers. I need to dynamically change the endpoint address on my silverlight client depending on the environment its in. I’m currently getting a very detailed 404 error (sarcasm) when I try to change the address through code or by manually updating the client config file.
However, when I right-click on the service reference and go to configure service on my client I can change the address and it works.
I have the following service.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DrawingServiceBasicHttp">
<readerQuotas maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<service behaviorConfiguration="md" name="My.DrawingService">
<endpoint address="Services"
binding="basicHttpBinding"
bindingConfiguration="DrawingServiceBasicHttp"
name="DrawingServiceEndPoint"
contract="MyServices.IDrawingService" />
<endpoint address="mex"
binding="mexHttpBinding"
bindingConfiguration=""
name="DrawingMex"
contract="IMetadataExchange" />
<behaviors>
<serviceBehaviors>
<behavior name="md">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
My client config
<bindings>
<basicHttpBinding>
<binding name="DrawingServiceEndPoint" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://MyHostName/Services/DrawingService.svc/Services"
binding="basicHttpBinding" bindingConfiguration="DrawingServiceEndPoint"
contract="EvalDrawingService.IDrawingService" name="DrawingServiceEndPoint" />
</client>
In Code trying to set the address:
EvalDrawingService.DrawingServiceClient client = new EvalDrawingService.DrawingServiceClient("DrawingServiceEndPoint", GetServiceAddress());
I have verified the address being spit out by GetServiceAddress() is there and that I can use the browser to verify it exists (not to mention I can connect to it using the wcftestclient).
The Exception:
{System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. —> System.Net.WebException: The remote server returned an error: NotFound. —> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c_DisplayClass4.b_1(Object sendState)
— End of inner exception stack trace —
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
— End of inner exception stack trace —
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase1.ChannelBase1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at EvaluaionAncillaryControl.EvalDrawingService.DrawingServiceClient.DrawingServiceClientChannel.EndGetEvalAreaDrawing(IAsyncResult result)
at EvaluaionAncillaryControl.EvalDrawingService.DrawingServiceClient.EvaluaionAncillaryControl.EvalDrawingService.IDrawingService.EndGetEvalAreaDrawing(IAsyncResult result)
at EvaluaionAncillaryControl.EvalDrawingService.DrawingServiceClient.OnEndGetEvalAreaDrawing(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}
I found these which looks promising:
http://omaralzabir.com/dynamically-set-wcf-endpoint-in-silverlight/
http://blogs.artinsoft.net/mrojas/archive/2011/03/23/dynamically-change-wcf-endpoint.aspx
Also, here’s some code from my server project where I can change the end point on the fly using channels. I haven’t tried it from Silverlight. it does work from the server side.
Here’s how I use it: