0
コードでWCFインターフェイス定義のエンドポイント、操作、およびパラメータをプログラムで使用するにはどうすればよいですか?WCFインターフェイス定義のエンドポイント、操作、およびパラメータを反復する方法
コードでWCFインターフェイス定義のエンドポイント、操作、およびパラメータをプログラムで使用するにはどうすればよいですか?WCFインターフェイス定義のエンドポイント、操作、およびパラメータを反復する方法
これは私が非常に長い間知りたかった質問であり、最終的にMicrosoftのMSDN Webサイトに必要な解決策を見つけました。早くそれを見つけたかっただけだ。私は以下の答えとリンクを提供します。
System.ServiceModel.Description OperationDescriptionクラスを使用します。
私のコードでServiceHostを取得しました。
Uri baseAddress = new Uri(OperationContext.Current.Host.BaseAddresses[0].AbsoluteUri);
ServiceHost sh = new ServiceHost(typeof(MyWebServiceClass), baseAddress);
次のコードはMicrosoft MSDN documentationです。私が必要とするものは次のコードです。
private void PrintDescription(ServiceHost sh)
{
// Declare variables.
int i, j, k, l, c;
ServiceDescription servDesc = sh.Description;
OperationDescription opDesc;
ContractDescription contractDesc;
MessageDescription methDesc;
MessageBodyDescription mBodyDesc;
MessagePartDescription partDesc;
IServiceBehavior servBeh;
ServiceEndpoint servEP;
// Print the behaviors of the service.
Console.WriteLine("Behaviors:");
for (c = 0; c < servDesc.Behaviors.Count; c++)
{
servBeh = servDesc.Behaviors[c];
Console.WriteLine("\t{0}", servBeh.ToString());
}
// Print the endpoint descriptions of the service.
Console.WriteLine("Endpoints");
for (i = 0; i < servDesc.Endpoints.Count; i++)
{
// Print the endpoint names.
servEP = servDesc.Endpoints[i];
Console.WriteLine("\tName: {0}", servEP.Name);
contractDesc = servEP.Contract;
Console.WriteLine("\tOperations:");
for (j = 0; j < contractDesc.Operations.Count; j++)
{
// Print the operation names.
opDesc = servEP.Contract.Operations[j];
Console.WriteLine("\t\t{0}", opDesc.Name);
Console.WriteLine("\t\tActions:");
for (k = 0; k < opDesc.Messages.Count; k++)
{
// Print the message action.
methDesc = opDesc.Messages[k];
Console.WriteLine("\t\t\tAction:{0}", methDesc.Action);
// Check for the existence of a body, then the body description.
mBodyDesc = methDesc.Body;
if (mBodyDesc.Parts.Count > 0)
{
for (l = 0; l < methDesc.Body.Parts.Count; l++)
{
partDesc = methDesc.Body.Parts[l];
Console.WriteLine("\t\t\t\t{0}",partDesc.Name);
}
}
}
}
}
}
ありがとうございました!関連する資料への実際のリンクを提供してください。 –
私の喜び。これはメインコードブロックの上の答えです。 –