私は石鹸構造で構築されたAPIを消費しています(私のものではありません)。
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<somePrefix:someNodeName xmlns="ulrWithNoPrefix" xmlns:somePrefix="urlWithPrefix"
xmlns:anotherPrefix="UrlForAnotherprefix xmlns:AttributePrefix="UrlForAttributePrefix>
<anotherPrefix:childNode1>value</anotherPrefix:childNode1>
<anotherPrefix:childNode2>value</anotherPrefix:childNode2>
<anotherPrefix:childNode3>value</anotherPrefix:childNode3>
<anotherPrefix:childNode3 AttributePrefix:AttributeName="attributeValue/>
</somePrefix:someNodeName>
</S:Body>
</S:Envelope>
そこから C# オブジェクトを構築しようとしています。確かに各ノードに移動し、内部テキストを抽出してカスタムタイプを入力できますが、これを実行できることは理解していました(タイプを作成する必要があります)。httpClient に組み込まれている逆シリアル化メカニズムを使用しようとしましたが、protobuf-net をダウンロードしてそこで運試しをしましたが、失敗しました。
接続を処理するための次の方法があります:
public void RunPostTask(string url, string req) { 文字列 res = ""; var client = new HttpClient(); HttpRequestMessage リクエスト = 新しい HttpRequestMessage(); request.Content = 新しい StringContent(req); request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
var task = client.PostAsync(url, request.Content).ContinueWith((TaskResponse) => { TaskResponse.Result.EnsureSuccessStatusCode(); var response = TaskResponse.Result; var ReadTask = response.Content.ReadAsStringAsync(); ReadTask.Wait(10000); res = ReadTask.Result; }).ContinueWith((err) => { if (err.Exception != null) { res = err.Exception.ToString(); } }); task.Wait(10000); }
res 文字列をデシリアライズしたい (典型的な構造は上に示されている)
また、HttpClient の使用方法が正しいかどうか、またはより良い設計が望ましいかどうかを知りたいですか?
ありがとうギラド