2017-07-21 11 views
-2

私はsoapメッセージを探しています。C#、 ここに私はコマンドプロンプトからsoapメッセージを作成しようとしているコマンドを使用してクライアントを作成しましたが、このコンセプトにはとても新しいので正しい方法を見つけることができません誰もこれに関してアイデアを持っていますか?C#でSOAPメッセージを作成するには?

+0

は、どのようなコマンドを使用するには、クライアントを作成するために実行しましたか?あなたはクライアントコードを共有できますか? SOAPメッセージを作成するために作成したコードは何ですか? –

+0

あなたが渡している場所、渡している場所、渡した理由、間違っていることは、コードを見ずにはわかりません。だから、あなたが問題の最も適切な解決策を提供する必要がある場合は、コードを共有してください。 –

答えて

1

サンプルコード、SOAPリクエストを作成するには

using System; 
using System.IO; 
using System.Net; 
using System.Xml; 

namespace UsingSOAPRequest 
{ 
    public class Program 
    { 
     static void Main(string[] args) 
     { 
      //creating object of program class to access methods 
      Program obj = new Program(); 
      Console.WriteLine("Please Enter Input values.."); 
      //Reading input values from console 
      int a = Convert.ToInt32(Console.ReadLine()); 
      int b = Convert.ToInt32(Console.ReadLine()); 
      //Calling InvokeService method 
      obj.InvokeService(a, b); 
     } 
     public void InvokeService(int a, int b) 
     { 
      //Calling CreateSOAPWebRequest method 
      HttpWebRequest request = CreateSOAPWebRequest(); 

      XmlDocument SOAPReqBody = new XmlDocument(); 
      //SOAP Body Request 
      SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?> 
      <soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema- instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> 
      <soap:Body> 
       <Addition xmlns=""http://tempuri.org/""> 
        <a>" + a + @"</a> 
        <b>" + b + @"</b> 
       </Addition> 
       </soap:Body> 
      </soap:Envelope>"); 


      using (Stream stream = request.GetRequestStream()) 
      { 
       SOAPReqBody.Save(stream); 
      } 
      //Geting response from request 
      using (WebResponse Serviceres = request.GetResponse()) 
      { 
       using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream())) 
       { 
        //reading stream 
        var ServiceResult = rd.ReadToEnd(); 
        //writting stream result on console 
        Console.WriteLine(ServiceResult); 
        Console.ReadLine(); 
       } 
      } 
     } 

     public HttpWebRequest CreateSOAPWebRequest() 
     { 
      //Making Web Request 
      HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(@"http://localhost/Employee.asmx"); 
      //SOAPAction 
      Req.Headers.Add(@"SOAPAction:http://tempuri.org/Addition"); 
      //Content_type 
      Req.ContentType = "text/xml;charset=\"utf-8\""; 
      Req.Accept = "text/xml"; 
      //HTTP method 
      Req.Method = "POST"; 
      //return HttpWebRequest 
      return Req; 
     } 
    } 
} 
+0

私は.configファイルに何かを追加する必要がありますか? – Madhav

関連する問題