0
C#コンソールアプリケーションでリクエストを投稿しようとしていますが、このエラーが発生しています。リクエストがSOAPUIで動作しているので、WSDLファイルがないので、コードに直接XMLをロードする必要があります(これはエラーがどこから来たのかと思われます)。C#コンソールアプリケーションでSOAPリクエストを送信するときのエラー
を私はこのSOAPリクエストを送信するために使用していますC#コンソールアプリケーションで次のように働いている
SOAPUI要求です。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace IMSPostpaidtoPrepaid
{
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.createSOAPWebRequest();
}
//Create the method that returns the HttpWebRequest
public void createSOAPWebRequest()
{
//Making the Web Request
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(@"http://127.1.1.0:9090/spg");
//Content Type
Req.ContentType = "text/xml;charset=utf-8";
Req.Accept = "text/xml";
//HTTP Method
Req.Method = "POST";
//SOAP Action
Req.Headers.Add("SOAPAction", "\"SOAPAction:urn#LstSbr\"");
NetworkCredential creds = new NetworkCredential("username", "pass");
Req.Credentials = creds;
Req.Headers.Add("MessageID", "1"); //Adding the MessageID in the header
string DN = "+26342720450";
string DOMAIN = "ims.telone.co.zw";
//Build the XML
string xmlRequest = String.Concat(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
"<soap:Envelope",
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
" xmlns:m=\"http://www.huawei.com/SPG\"",
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"",
" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">",
" <soap:Body>",
"<m:LstSbr xmlns=\"urn#LstSbr\">",
" <m:DN>", DN, "</ m:DN>",
" <m:DOMAIN>", DOMAIN, "</ m:DOMAIN>",
" </m:LstSbr>",
" </soap:Body>",
"</soap:Envelope>");
//Pull Request into UTF-8 Byte Array
byte[] reqBytes = new UTF8Encoding().GetBytes(xmlRequest);
//Set the content length
Req.ContentLength = reqBytes.Length;
//Write the XML to Request Stream
try
{
using (Stream reqStream = Req.GetRequestStream())
{
reqStream.Write(reqBytes, 0, reqBytes.Length);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception of type " + ex.GetType().Name + " " + ex.Message);
Console.ReadLine();
throw;
}
//Headers and Content are set, lets call the service
HttpWebResponse resp = (HttpWebResponse)Req.GetResponse();
string xmlResponse = null;
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
xmlResponse = sr.ReadToEnd();
}
Console.WriteLine(xmlResponse);
Console.ReadLine();
}
}
}
それを見て – nktsamba
ちょっと@nktsamba、あなたはそれを解決する機会を得ましたか? –