2013-03-14 2 views
8

내가 자신의 어셈블리의 손으로 쓴 WCF 프록시를 가지고, 그것은 매우 간단합니다구성 파일과 Powershell 스크립트에서 사용자 지정 WCF 프록시를 사용하는 방법?

public class MyServiceClient : ClientBase<IMyService>, IMyService 
{ 
    public MyServiceClient() 
    { 
    } 

    public MyServiceClient(string endpointConfigurationName) : 
     base(endpointConfigurationName) 
    { 
    } 
} 

내가 PowerShell 스크립트로이로드 오전 : 나는 다음 앱을 설정하려고

Add-Type -Path "$LocalPath\MyService.Client.dll" 
Add-Type -Path "$LocalPath\MyService.Contracts.dll" 

의 .config 클라이언트가 아니라 스크립트 자체보다, 설정에 정의 된 엔드 포인트 인스턴스화 할 수 있도록 (SO에 other posts 당) :

[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$LocalPath\MyService.Client.dll.config") 

I AppDomain을 확인했으며 구성 파일이 ConfigurationFile 속성으로 설정되었습니다.

나는 클라이언트의 인스턴스를 만들 :

Exception calling ".ctor" with "1" argument(s): "Could not find endpoint element with name 'MyServiceHttpEndpoint' and contract 'MyService.Contracts.IMyService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element."

어떤 아이디어 :

$endpointName = "MyServiceHttpEndpoint" # defined in the app.config file 
$myclient = New-Object MyService.Client.MyServiceClient($endpointName) 

그것은 말 전복을? 스크립트 파일에 수동으로 엔드 포인트를 작성하고 싶지 않습니다. config에서 읽어야합니다.

+1

오류가 발생했습니다 : 구성 파일을보고 "MyServiceHttpEndpoint"라는 끝점을 찾을 수 없습니다. 의미있는 도움이 필요하면 실제 설정 파일을 게시해야합니다. – ErnieL

+0

또한 '응용 프로그램에서 구성 파일을 찾을 수 없기 때문에 발생했을 수 있습니다.'라는 것이 문제입니다. config 파일은 문제가 없으며 Powershell 외부에서 작동합니다. – MalcomTucker

+0

AppDomain을 확인했고 설정 파일이 존재하고'AppDomain.ConfigurationFile' 속성을 찾았습니다. 설정 파일을 클라이언트 프록시에 묶을 수 없습니다. 구성 추가 ... – MalcomTucker

답변

0

어셈블리가 32 비트 또는 64 비트 대상으로 구축 되었습니까?

여러 경우에 32/64 문제가 발생했습니다.

64 비트 OS에서 실행중인 경우 64 비트 (일반)와 32 비트 (32 외부 어셈블리가 필요할 때 interresting)의 두 PowerShell이 ​​있음을주의하십시오.

0

전체 구성을 게시하는 것이 더 쉽지만 다음 섹션이 누락 된 것처럼 들립니다.

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding"> 
      <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="ServiceAddress" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" 
     contract="MyService.Contracts.IMyService" name="MyServiceHttpEndpoint" /> 
    </client> 
</system.serviceModel> 

물론 그렇지 않겠지 만.

그래서 시도하고 PowerShell은 응용 프로그램이 올바르게 설정을 따기되어 있는지 확인 할 수 있습니다

...

예상하여 PowerShell을 파일에 이런 식으로 뭔가를 추가로 파워 쉘의 앱이 설정을 따기 경우 확인하려면 :

Get-Content $LocalPath\MyService.Client.dll.config | foreach {Write-Output $_} 

구성 문제가 아니라면 우리는 이에 동의 할 수 있다고 생각합니다.

dll은 config에서 설정을 볼 수 있습니까? 지금까지 우리는 powershell이 ​​config를 볼 수 있고 dll을 호출 할 수 있음을 알고 있습니다.

config는 dll과 같은 위치에 있습니까?

add-type은 우리가 기대하지 않는 것을 수행합니까? msdn 문서를 보면 추가 형식 인 것 같습니다.

Windows PowerShell 세션에 Microsoft .NET Framework 형식 (클래스)을 추가합니다.

클래스가 현재 powershell 세션에있는 경우 정상적으로 설정에 액세스 할 수 있습니까? 나는 모른다.

아마도 [Reflection.Assembly]::LoadFrom이나 그렇지 않은 경우 add-type을 시도해보십시오.

정확한 대답이 없습니다. 두려워하지만 내 얘기가 다소 도움이 되었기를 바랍니다. 이 같은 코드를 보이게 PowerShell을

에있을 때

0

는 바인딩의 유형을 누락처럼, 그것은은 BasicHttpBinding해야 같다 :

$endpointName = "MyServiceHttpEndpoint" 
$httpBinding = new-object System.ServiceModel.WSHttpBinding 
$myclient = New-Object MyService.Client.MyServiceClient($httpBinding, $endpointName) 
0

길을한다는 점에서 차이가있는 것 같습니다 파워 쉘 Powershell ISE가이를 처리합니다.

ISE (적어도 사용하고있는 버전)를 사용하면 강제로 다시로드하기 위해 구성을 지워야합니다. 하지만 .dll.config 파일의 내용을 powershell ISE config에 넣을 수도 있습니다. 그러나, 그것은 더러운 것처럼 보입니다. 아래에 게시 된 코드가 작동합니다. 나는이 문제를 인터넷 검색으로 찾아 냈다.

# $dllPath is the path to the dll we want to load 
# first point to the correct config file 
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "$dllPath.config") 

# PowerShell ISE is a PITA we have to override the config 
if ($psISE -ne $null) { 
    Add-Type -AssemblyName System.Configuration 
    [Configuration.ConfigurationManager].GetField("s_initState", "NonPublic, Static").SetValue($null,0) 
    [Configuration.ConfigurationManager].GetField("s_configSystem", "NonPublic, Static").SetValue($null,$null) 
    ([Configuration.ConfigurationManager].Assembly.GetTypes() | where {$_.FullName -eq "System.Configuration.ClientConfigPaths"})[0].GetField("s_current", "NonPublic, Static").SetValue($null, $null) 
} 

#Now load the DLL 
$null = [Reflection.Assembly]::LoadFrom($dllPath) 

# DLL and Config should be loaded - test 
0

가능한 경우 설정 파일을 모두 건너 뛰는 것이 좋습니다. API에서 MEX 또는 WSDL 끝점을 제공하는 경우 쿼리를 통해 프록시를 만들고 WsdlImporter을 사용하여 메모리에 바인딩 구성을 작성하십시오. 그 시점에서 필요한 경우 메모리에서 수정할 수 있습니다.

이 작업은을 사용하는 보안 토큰 서비스와 통합되어 있기 때문에 구성 WCF 서비스 측면에서 매우 무거운 작업입니다.

question 나는 갤러리에서 사용할 수있는 WcfPS 모듈을 사용해 보았습니다. 다른 질문과 겹치기 때문에 나는 그것의 일부를 인용 할 것이다. 모듈의 code

오픈 소스이며, 비록 그 스크립트 그것은 System.ServiceModelSystem.IdentityModel 및 어셈블리에서 .NET 프레임 워크 클래스 및 어셈블리에 크게 의존한다. 이 어셈블리의 api 대부분이 .NET 표준 2에서 사용할 수 없기 때문에 언급합니다. 따라서이 모듈은 불행하게도 Windows가 아닌 운영 체제에서 작동하지 않습니다. 내 게시물 WCFPS - PowerShell module to work with SOAP endpoints에서 자세한 내용을 읽을 수도 있습니다.

당신이 비주얼 스튜디오없이 구성에 사용 인라인 .NET 유형의 수입도 프록시가 필요하지 않습니다이 방법으로 README

#region Initialize the channel/client 
$svcEndpoint="http://myserviceprovider/Service1.svc" 

$wsImporter=New-WcfWsdlImporter -Endpoint $svcEndpoint -HttpGet 
$proxyType=$wsImporter | New-WcfProxyType 

# select the endpoint and implicitly the binding from the imported configuration 
$endpoint=$wsImporter | New-WcfServiceEndpoint -Endpoint $svcEndpoint 
$channel=New-WcfChannel -Endpoint $endpoint -ProxyType $proxyType 
#endregion 

#region Use the channel/client 
$channel.Method1() 
$channel.Method2() 
#endregion 

의 예입니다. 대부분의 경우 유스 케이스에 맞게 조정해야합니다. 모듈의 기능을 향상시킬 수 있다면 pull 요청을 제출하십시오.

관련 문제