請幫助...我要瘋了....我有一個wcf服務存在於幾個不同的服務器上。我需要根據其中的環境動態更改我的Silverlight客戶端上的端點地址。當我嘗試通過代碼更改地址或手動更新客戶端配置文件時,我目前正在獲取非常詳細的404錯誤(諷刺)。Silverlight 3 WCF多服務器
但是,當我右鍵單擊服務引用並轉到在我的客戶端上配置服務時,我可以更改地址並且它可以工作。
我有以下服務。
<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>
我的客戶端配置
<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>
在代碼中嘗試設置地址:
EvalDrawingService.DrawingServiceClient client = new EvalDrawingService.DrawingServiceClient("DrawingServiceEndPoint", GetServiceAddress());
我已經驗證通過GetServiceAddress()
被吐出的地址是存在的,我可以使用瀏覽器來驗證它是否存在(更不用說我可以連接t了它使用wcftestclient)。
例外:
{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.ClientBase
1.ChannelBase
1.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)}
當您在config中更改了端點地址時發生了什麼?這應該工作,我相信 – Richard 2011-03-30 20:08:38
@理查德 - 看到我的編輯,謝謝。 – AGoodDisplayName 2011-03-30 20:17:29
兩個建議 - 請發佈確切的錯誤消息,你可能想使用提琴手來查看失敗的請求。 – rboarman 2011-04-11 19:52:47