からWCFサービスのURLを更新することです終点。これを参照してくださいhereとblog postにリンクします。
ぼんやりしたサービスに接続するための自分の抽象基本クラスは、その記事に基づいていました。私は(ステージングを参照する必要はありません
this.roleName = "WebServiceRole";
this.endpointName = "HttpInternal";
this.serviceName = "services/Accounts.svc";
:
#region Channel
protected String roleName;
protected String serviceName;
protected String endpointName;
protected String protocol = @"http";
protected EndpointAddress _endpointAddress;
protected BasicHttpBinding httpBinding;
protected NetTcpBinding tcpBinding;
protected IChannelFactory channelFactory;
protected T client;
protected virtual AddressHeader[] addressHeaders
{
get
{
return null;
}
}
protected virtual EndpointAddress endpointAddress
{
get
{
if (_endpointAddress == null)
{
var endpoints = RoleEnvironment.Roles[roleName].Instances.Select(i => i.InstanceEndpoints[endpointName]).ToArray();
var endpointIP = endpoints.FirstOrDefault().IPEndpoint;
if(addressHeaders != null)
{
_endpointAddress = new EndpointAddress(new Uri(String.Format("{1}://{0}/{2}", endpointIP, protocol, serviceName)), addressHeaders);
}
else
{
_endpointAddress = new EndpointAddress(String.Format("{1}://{0}/{2}", endpointIP, protocol, serviceName));
}
}
return _endpointAddress;
}
}
protected virtual Binding binding
{
get
{
switch (protocol)
{
case "tcp.ip":
if (tcpBinding == null) tcpBinding = new NetTcpBinding();
return tcpBinding;
default:
//http
if (httpBinding == null) httpBinding = new BasicHttpBinding();
return httpBinding;
}
}
}
public virtual T Client
{
get
{
if (this.client == null)
{
this.channelFactory = new ChannelFactory<T>(binding, endpointAddress);
this.client = ((ChannelFactory<T>)channelFactory).CreateChannel();
((IContextChannel)client).OperationTimeout = TimeSpan.FromMinutes(2);
var scope = new OperationContextScope(((IContextChannel)client));
addCustomMessageHeaders(scope);
}
return this.client;
}
}
#endregion
そして、私はそれを(例えば)以下の変数を渡す派生クラス内:それは、このようなチャネルクレートに役割の発見を使用していますまたは制作)URLをまったく使用しないでください。
詳細はこちら私の答えを参照してください:MSは、一貫性のあるステージングURLやIPのためのオプションを追加したい人のためAdd WCF reference within the same solution without adding a service reference
を、MSのAzureフィードバックサイト上で、それのための提案があります。 [投票やコメントを追加できます](http://feedback.windowsazure.com/forums/169386-cloud-services-web-and-worker-role-/suggestions/1282603-pick-a-dns-name-ステージング用)。 – Co7e