2016-08-19 10 views
1

私はGoogleの方法を試してきましたが、私はこの質問で頭を少し傷つけることになります。UWPを使用してSOAPに情報を保存します

私はコードに関しては遅い学習者ですが、私は本当にあきらめません。良い文書がある限り、私は一般的に私の方法を学ぶことができます。

私の現在の質問は、UWPアプリケーションからSOAPサービスにデータを送信することを解決します。データを取得することは、簡単にドキュメントを見つけることができます。しかし、貯蓄はまったく別の問題です。

私はここでも最後の2日間は見つけようとしましたが、それほど多くは与えられていません。

私はC#を使用してUWPアプリケーションからSOAPサービスにデータを送信するヒントやサンプルコードを誰にでも教えていただけますか?

データを送信したいXAMLのコード行は非常に簡単です。

<textbox>Int</textbox 
<textbox>Decimal?</textbox 
<textbox>String</textbox 
<button name=send /> 

答えて

0

誰も私のヒントや私たちはSOAPサービスにUWPアプリからのデータを送信するためにC#を使用するコード例を与えることができますか?

まず、あなたは、SOAPサービスからデータを呼び出す方法を、一般的な方法はHttpClientクラスを使用することであると表示される場合があります。

あなたがデータを送信する必要がある場合、また、このクラスを使用して、我々は背後にあるコードからSOAPリクエストを構築する必要があり、ここでは簡単なデモです:

このようなテストのSOAPリクエスト:

<?xml version=""1.0"" encoding=""utf-8""?> 
    <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""> 
     <s:Body> 
      <Save xmlns=""http://TestService/""> 
       <textbox>txt1</textbox> 
       <textbox>txt2</textbox> 
       <textbox>txt3</textbox> 
      </Save> 
     </s:Body> 
    </s:Envelope> 

は、コードサンプル:

private async void btn_Send_Click(object sender, RoutedEventArgs e) 
    { 
     await AddNumbersAsync(new Uri("http://xxxxxx/TestService.asmx"), "txt1", "txt2", "txt3"); 
    } 

    public async Task<int> AddNumbersAsync(Uri uri, string t1, string t2, string t3) 
    { 
     var soapString = this.ConstructSoapRequest(t1, t2, t3); 
     using (var client = new HttpClient()) 
     { 
      client.DefaultRequestHeaders.Add("SOAPAction", "http://TestServiceService/ITestServiceService/Save"); 

      var content = new HttpStringContent(soapString, Windows.Storage.Streams.UnicodeEncoding.Utf8, "text/xml"); 
      using (var response = await client.PostAsync(uri, content)) 
      { 
       var soapResponse = await response.Content.ReadAsStringAsync(); 
       return this.ParseSoapResponse(soapResponse); 
      } 
     } 
    } 

    private string ConstructSoapRequest(string t1, string t2, string t3) 
    { 
     return String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> 
<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""> 
    <s:Body> 
     <Save xmlns=""http://TestService/""> 
      <textbox>{0}</textbox> 
      <textbox>{1}</textbox> 
      <textbox>{2}</textbox> 
     </Save> 
    </s:Body> 
</s:Envelope>", t1, t2, t3); 
    } 

    private int ParseSoapResponse(string response) 
    {//Custom this function based on your SOAP response 
     var soap = XDocument.Parse(response); 
     XNamespace ns = "http://TestService/"; 
     var result = soap.Descendants(ns + "SaveResponse").First().Element(ns + "SaveResult").Value; 
     return Int32.Parse(result); 
    } 
関連する問題