내가 사용하는 열려있어 그러나 이것은 나를 위해 작동 더 나은 방법이있을 수 있으며,이 유연.
웹 응용 프로그램 Web.config에서 AppSettings에 변수를 추가하고 기본 URL을 저장합니다. SVC 파일의 위치를 저장하지 않는다는 것을 알기 때문에 나중에 추가 할 것입니다. 이것은 내가 일반적으로 가리키는 SVC가 여러 개 있기 때문입니다. 다르게 선택할 수도 있습니다. 내 웹 응용 프로그램의 웹 페이지에서
<appSettings>
<add key="ServiceURI" value="http://localhost:64457/"/>
</appSettings>
는 InitParms라는 PARAM를 추가, 이것은 당신이 키의 목록을 추가 할 수 있습니다,합니다 (XAP 파일을 읽어들이 쉼표로 구분) 쌍의 값
<div id="silverlightControlHost">
<object data="data:application/x-silverlight," type="application/x-silverlight-2"
width="100%" height="100%" ID="Xaml1" >
<param name="InitParams" value="ServiceURI=<%= ConfigurationManager.AppSettings("ServiceURI") %>" />
실버 App.xaml.vb에서
는, 리소스에 모든 InitParms을로드하거나 위치를 내 XAML 파일의에서 다음
Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
If e.InitParams IsNot Nothing Then
For Each k As Generic.KeyValuePair(Of String, String) In e.InitParams
Me.Resources.Add(k.Key, k.Value)
Next
End If
원하는 이제까지 내가 구성된 URI로 서비스를 초기화 할 수 있습니다, 나는이 이러한 제안 우수한이
Private Sub InitializeService()
Dim uri As String = App.Current.Resources("ServiceURI")
If uri Is Nothing OrElse uri = String.Empty Then
'if there is no value added in the web.config, I can fallback to default values
_client = New ServiceClient
Else
'Notice I hardcoded the location of the SVC files in the client and append there here, you may choose not to do this
Dim uri_withservice As String = uri & "svc/secure/Service.svc"
_client = New ServiceClient("CustomBinding_Service", New EndpointAddress(uri_withservice))
End If
End Sub
이 솔루션은 내가 아는 한 최선입니다. 다른 하드 코딩 된 솔루션은 나에게 적합하지 않습니다. – helios456