몇 달 전 프로젝트에서 WCF 메서드와 그 매개 변수를 드롭 다운에 표시하려고했습니다. 그 당시 저는 Add Service Reference를 사용하여 프록시를 만들고 코드에 서비스 인터페이스를 하드 코딩했습니다. How can I show all the methods that are available in my WCF in a dropdown 하지만 프록시를 동적으로 만들려고 할 때 아래 코드가 작동하지 않습니다. 제게 정의 된 방법만을 보여 주도록 도와주세요.동적으로 생성 된 프록시에 대해 WCF 메서드를 필터링 할 수 없습니다.
// Using Dynamic Proxy Factory by Vipul Modi @ Microsoft
DynamicProxyFactory factory = new DynamicProxyFactory(txtService.Text);
// endpoints.
string sContract = "";
foreach (ServiceEndpoint endpoint in factory.Endpoints)
{
sContract = endpoint.Contract.Name; //this is the service interface name, IAccountInfoService
}
DynamicProxy proxy = factory.CreateProxy(sContract);
Type proxyType = proxy.ProxyType;
MethodInfo[] methods = proxyType.GetMethods();
foreach (var method in methods)
{
//if (method.GetCustomAttributes(typeof(OperationContractAttribute), true).Length == 0)
// continue;
string methodName = method.Name;
ddlMethods.Items.Add(methodName);
}
이 코드는 method.GetCustomAttributes 주석 (대해서 typeof (OperationContractAttribute를)을, TRUE) .Length가 작동하지 않습니다. 어떤 방법도 보여주지 않습니다. 제가 주석으로 작성하면 결과는 모든 메소드와 변수입니다. 나는 그것을 단지 사용자 정의 된 방법으로 제한하고 싶다.
실제로 메소드 이름을 얻으려면 다음에 정의 된 각 메서드의 매개 변수 목록 서비스 계약. ContractDescription 및 OperationDescription 사용 방법 목록을 얻을 수 있지만 매개 변수를 가져 오는 방법을 모르십니까? –