我有以下用C#编写的程序来使用Web服务。
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.InvokeService();
}
public HttpWebRequest CreateSOAPWebRequest()
{
HttpWebRequest Req =
(HttpWebRequest)WebRequest.Create(@"https://MyWebService");
Req.ContentType = "text/xml;charset=\"utf-8\"";
Req.Accept = "text/xml";
Req.Method = "POST";
return Req;
}
public void InvokeService()
{
HttpWebRequest request = CreateSOAPWebRequest();
XmlDocument SOAPReqBody = new XmlDocument();
SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-
instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"">
<soapenv:Header/>
<soapenv:Body>
<Content>..... </Content>
</soapenv:Body>
</soapenv:Envelope>");
using (Stream stream = request.GetRequestStream())
{
SOAPReqBody.Save(stream);
}
using (WebResponse Serviceres = request.GetResponse())
{
using (StreamReader rd = new
StreamReader(Serviceres.GetResponseStream()))
{
var ServiceResult = rd.ReadToEnd();
Console.WriteLine(ServiceResult);
Console.ReadLine();
}
}
}
}
我现在想要将WSDL附加到此soap请求。 我所拥有的是.wsdl文件。我使用“SOAP UI”尝试了这个SOAP请求并且它有效,我收到了响应。 好像我需要在SOAP标头中指定方法,但我无法做到这一点。我只能将.WSDL文件放在项目文件夹中的某个位置。
有人可以帮助我得到正确的答案吗?