Sys*_*Sys 8 c# xsd web-services
我们有一个新的会计系统,为外部客户提供Web服务接口.我要访问的一个接口,但没有WSDL所以我创建通过使用HttpWebRequest的请求,它工作正常.
然而,为了简化请求的创建和解析响应,我想创建某种自动化功能.我在XSD文件中有请求和响应结构.有任何想法吗?
请求创建:
public void SendRequest()
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
++ structure type inserted here ++
</soap:Body>
</soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
Run Code Online (Sandbox Code Playgroud)
好吧,如果您确实无法获得正确的 WSDL 文件,但有 XSD:s,您可能可以使用该xsd.exe工具来创建映射到您的请求和响应类型的类。
像这样的东西(在 Visual Studio 命令提示符中运行它)
xsd.exe TheRequest.xsd /c /n:Your.Namespace
xsd.exe TheResponse.xsd /c /n:Your.Namespace
Run Code Online (Sandbox Code Playgroud)
但实际上,尽力找到 WSDL,它会让您的生活变得更加轻松。