2017-02-21 8 views
0

のServiceContract & OperationContractは以下のようになります。WCFでタイプ "アセンブリ"を返す方法は?

[ServiceContract] 
public interface IAssemblyResolver 
{ 

    [OperationContract] 
    Assembly LoadAssembly(AssemblyLoadRequest loadRequest); 
    // TODO: Add your service operations here 
} 

タイプAssemblyを戻しながら、私は、トレースログ内のエラーの下に取得する:クライアント側で

There was an error while trying to serialize parameter http://tempuri.org/:LoadAssemblyResult . The InnerException message was 'Type 'System.Reflection.RuntimeAssembly' with data contract name 'RuntimeAssembly: http://schemas.datacontract.org/2004/07/System.Reflection ' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.'. Please see InnerException for more details.

私はエラーの下に出る:

Additional information: An error occurred while receiving the HTTP response to http://localhost:8769/AssemblyResolverService.svc . This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

+1

dllバイナリを返すのですか? – Wojtpl2

+0

あなたがしようとしていることを説明してください。これはうまくいかないようです。 WCFサービスがクライアントのDLLをホストするようにするには、DLLとその依存関係をクライアントにストリーミングする必要があります。 – CodeCaster

+0

共有場所からアセンブリを読み込み、単純にそれを返すことにしました。 – Amit

答えて

0

アセンブリをAssembly.FullNameを使用して文字列に手動でシリアル化する必要があります。それを返す。アセンブリに文字列を逆シリアル化する場合は、Assembly.Load methodを使用します。

サーバーの例:

クライアント側で使用
string LoadAssembly(AssemblyLoadRequest loadRequest) 
{ 
    return ....Assembly.FullName; 
} 

Assembly.Load(LoadAssembly(....)); 

あなたは(それがクライアント側に存在していない場合)ファイルとしてアセンブリをシリアル化する必要がある場合は、あなたがすることができますこれを試してください:

サーバーの例:

クライアント側で使用
byte[] LoadAssembly(AssemblyLoadRequest loadRequest) 
{ 
    return File.ReadAllBytes(....Assembly.Location); 
} 

var assembly = Assembly.Load(LoadAssembly(....)); 

をしかし、あなたはバイト配列からアセンブリをロードする場合は、このアセンブリから型を仕事のためにリフレクションを使用する必要があります。

+1

私は、バイト[]を返すほうがいいと思うし、クライアント側では単にAssembly.Load(bytes)を実行します。 – Amit

+1

アセンブリがクライアントに存在する必要はありません。そのFullNameを送信することで、アセンブリを「シリアライズ」していないことになります。 – CodeCaster

+1

完全なアセンブリのシリアル化のために私の返信を更新しました。 –

関連する問題