WebサービスにSOAPリクエストを送信したときに、この例外が発生しました。 "リモートサーバーがエラーを返しました:(500)Internal Server Error"。 WebServiceには2つのパラメータ(int a、int b)があります。私はそれらの2つのパラメータを削除する場合は、私は例外を取得しません。SOAPリクエストをWebServiceに送信するエラー500
これはSOAP + WSの初めての経験です。私は何を間違えますか? お時間を頂きましてありがとうございます。
編集: 私の大学は私のコードでエラーを見つけました。無効なヘッダーを付けて送信していました。ここで
が不足しているヘッダー部分である:
request.Headers.Add("SOAPAction", "http://tempuri.org/Add");
はまた、私が使用しているURLが間違っていました。 間違っ:正しい
http://localhost:62830/Service1.asmx/Add
:ここ
http://localhost:62830/Service1.asmx
は、ここでのWebService
private void button2_Click(object sender, EventArgs e)
{
var url = UrlTextBox.Text;
var xml_file_path = FileTextBox.Text;
XmlDocument xml_doc = new XmlDocument();
xml_doc.Load(xml_file_path);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "text/xml";
request.Accept = "text/xml";
request.Timeout = 30 * 1000;
Stream request_stream = request.GetRequestStream();
xml_doc.Save(request_stream);
request_stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream r_stream = response.GetResponseStream();
StreamReader response_stream = new StreamReader(r_stream, System.Text.Encoding.Default);
string sOutput = response_stream.ReadToEnd();
ResultTextBox.Text = sOutput;
}
XMLファイルにSOAPを送る私のコード クライアントです
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<add xmlns="http://tempuri.org/" >
<a>5</a>
<b>10</b>
</add>
</soap12:Body>
</soap12:Envelope>
そしてここにWebServiceのコード
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
}
多分文字列としてそれらを読んで、その後、int型に変換することが –
私の計画は、後でWebサービスへの項目の複雑なコレクションを送信することで役立つかもしれません。文字列としてそれらを読むことは、それらを複雑なクラスに変換する作業の多くであろう。 – Jack