11

現在、powershell の機能を調査していますが、解決できない問題に遭遇しました。簡単なヒントをいただければ幸いです =)

私の目標: powershell v2.0 から (できれば new-webserviceproxy コマンドレットを使用して) WCF サービス (MTOM メッセージ エンコーディングで構成) からメソッドを呼び出す

私の問題: メッセージ エンコーディングが Mtom に設定されている場合、new-webserviceproxy コマンドレットはサービスの応答を正しく解析できません。次のエラーが表示されます。

パワーシェル:

$proxyObject = New-WebServiceProxy -URI "http://myserver.com/AccessService.svc?wsdl"
$proxyObject.TestWebServiceConnection()

"0" 個の引数を指定して "TestWebServiceConnection" を呼び出し中に例外が発生しました: "クライアントが 'multipart/related; type="application/xop+xml" の応答コンテンツ タイプを検出しました;start="<http://tempuri.org/0> ";boundary="uuid:
4001d529-32b9-4560-9f4b-550c35c67b03+id=4";start-info="text/xml"', but expected 'text/xml'.
要求はエラー メッセージで失敗しました:
- -
--uuid:4001d529-32b9-4560-9f4b-550c35c67b03+id=4
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml; charset=utf-8;type="text/xml"
<s:封筒 xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:本文>
< TestWebServiceConnectionResponse xmlns="http://myserver.com/">
<TestWebServiceConnectionResult>成功</TestWebServiceConnectionResult>
</TestWebServiceConnectionResponse>
</s:Body>
</s:Envelope>
--uuid:4001d529-32b9-4560-9f4b-550c35c67b03+id=4--
--."
行: 1 文字:38
+ $proxyObject.TestWebServiceConnection <<<< () >> error.txt
+ CategoryInfo : NotSpecified: (:) []、MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

他のクライアントや Microsoft が提供する wcfclient ツールを介して WCF サービスを利用できることに注意してください。TestWebServiceConnectionResultがsuccessを返したことがわかりますが、プロキシ オブジェクトが応答を解析できたようには見えません。

動作:

<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</振る舞い>
</serviceBehaviors>

バインディング(タイムアウト値/リーダー クォータとメッセージ サイズは、それらの値の順列が私の問題に関連していないように見えるため、除外しました):


<basicHttpBinding>
<binding name="basicHttpEndpointBinding" messageEncoding="Mtom">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</basicHttpBinding>

サービス

<service behaviorConfiguration="MyServiceBehavior" name="MyService.AccessService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpEndpointBinding" name="basicHttpEndpointAccessService" bindingNamespace="http://myserver.com/" contract= "MyService.IAccessService"/>
<endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="basicHttpEndpointBinding" name="mexEndpointAccess" contract="IMetadataExchange"/>
</service>
4

2 に答える 2

7

これを書いている時点では、New-WebServiceProxyMTOM が有効になっている WCF サービスでコマンドレットをうまく使用できていません。コマンドレットがサポートしているようには見えません。私の回避策svcutil.exeは、wsdl に対して実行し、 csc.exe. 次に、生成されたアセンブリを PowerShell ランタイムにロードし、プロキシ クラスのエンドポイントとバインディングを手動で構成しました。

wsdl から .cs ファイルを生成します。

$svcUri = "http://yourdomain/yourService.svc?wsdl";
$csFile = $className + '.cs';   # The name of the generated .cs file
$dllName = [System.IO.Path]::Combine($temp, $className + ".dll")
$svcUtilresult = svcutil.exe /noConfig /out:$csFile $svcUri

PowerShell の PATH に含まれていない可能性があることに注意svcutil.exeしてください。csc.exeこれを PATH に追加するか、フル パスを使用できます。Svcutil内で見つけることができますMicrosoft SDKs\Windows\<version>\bincsc.exeあなたの%windir%Microsoft .Netフォルダにあります

.cs ファイルを生成したら、それを dll にコンパイルする必要があります。

&"csc.exe" /t:library /out:$dllName $csFile

コンパイルされた dll を powershell にロードします。

$fileStream = ([System.IO.FileInfo] (Get-Item ".\$dllName")).OpenRead()
$dllBytes = new-object byte[] $fileStream.Length
$fileStream.Read($dllBytes, 0, $fileStream.Length)
$fileStream.Close()

[System.Reflection.Assembly]::Load($dllBytes)

PowerShell でプロキシ クライアントをインスタンス化します。

# Load System.ServiceModel, which can be found in your Framework\v3.0\Windows Communication Foundation folder
[System.Reflection.Assembly]::LoadFile($pathToSystemServiceModel)

# className is the name of your service
$serviceClientName = $className + "Client"

$basicHttpBinding = New-Object System.ServiceModel.BasicHttpBinding
$basicHttpBinding.MessageEncoding = [System.ServiceModel.WSMessageEncoding]::Mtom

$endPoint = New-Object System.ServiceModel.EndpointAddress($svcUri)
$wsClient = New-Object $serviceClientname($basicHttpBinding, $endPoint)
于 2012-04-04T22:09:08.560 に答える
1

私は同様の問題を抱えていました。ただし、たまたま ClientBase で生成されたコードがローカル アセンブリにコンパイルされていました。

私の解決策は次のとおりです。

add-type -path "..\..\bin\MYassemblyWithWCFCLient.dll"
$binding = new-object system.servicemodel.basichttpbinding
$binding.MessageEncoding = "Mtom"
$endpoint = new-object System.ServiceModel.EndpointAddress("http://whodunit.oops/mtomandjerry.svc")
$regProxy = new-object MySpecialNamespace.OopsServiceContractClient($binding, $endpoint)
于 2013-05-11T00:31:02.223 に答える