WCFサービスのエンドポイントを変更する

WCFサービスをデプロイする、などの理由からWCFサービスのURLが変更になることがあります。その時は、Sivlerlight側も変更に合わせて修正を行う必要があります。


このとき、WCFサービス側はクロスドメイン設定されている必要があります。詳細は、他ドメインのWebサービスにアクセスする方法 - y_maeyamaの日記をご参照ください。

ServiceReferences.ClientConfigファイル

SilverlightアプリケーションのWCFサービスのエンドポイントは、ServiceReferences.ClientConfigファイルに定義されています。このServiceReferences.ClientConfigファイルは、XAPファイルの直下に配置される必要があります。他の場所に置くと、Silverlightアプリケーションはファイルを認識できません。プロジェクトで言うと、メインのプロジェクトン直下に配置されることになります。

ServiceReferences.ClientConfigファイルを開くと、以下のようになっています。

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IHelloWorldService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:52627/HelloWorldService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHelloWorldService"
                contract="HelloWorld.IHelloWorldService" name="BasicHttpBinding_IHelloWorldService" />
        </client>
    </system.serviceModel>
</configuration>

endpointタグのaddress属性を変更するとWCFサービスの参照先が変更されます。例えば、

<endpoint address="http://localhost:52627/HelloWorldService.svc"/>

<endpoint address="http://localhost/Hello/HelloWorldService.svc"/>

などにします。