2011-01-03 1 views
0

몇 달 전 프로젝트에서 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가 작동하지 않습니다. 어떤 방법도 보여주지 않습니다. 제가 주석으로 작성하면 결과는 모든 메소드와 변수입니다. 나는 그것을 단지 사용자 정의 된 방법으로 제한하고 싶다.

답변

0

은 내가 DynamicProxyFactory에 대해 아무것도 몰라요하지만 http://blogs.msdn.com/b/vipulmodi/archive/2006/11/16/dynamic-programming-with-wcf.aspx보고 그것은 나를

1) 프록시 나던 실제로 속성과 방법을 방출 있다고 생각합니다. 그럴 필요는없는 것 같지만 코드를 스스로 조정하여 그 일이 가능할 것이라고 생각합니다.

2) 당신은 단지 메소드 이름의 목록을 원한다면, 당신이 factory.Contracts에서 해당를 얻을 수 있습니다 보인다

+0

실제로 메소드 이름을 얻으려면 다음에 정의 된 각 메서드의 매개 변수 목록 서비스 계약. ContractDescription 및 OperationDescription 사용 방법 목록을 얻을 수 있지만 매개 변수를 가져 오는 방법을 모르십니까? –

관련 문제