![](/img/trans.png)
[英]Just started learning C# & ASP.NET - strange syntax (to me) and I don't know what it is
[英]I don't know how to do a Soap Request using C# ASP.NET
我已经尝试了几个小时向我的 Soap 客户端 (SoapUI) 发出请求,阅读文档或回收代码(是的,抱歉),但我无法发出简单的请求。
我想做的很简单:
就这样。
一些代码:
//Receive parameters from Html
[HttpPost]
public ActionResult ConexionWS(string customerId, string mail)
//Connect to client with the authentication
SoapClient client = new SoapClient(binding, wsdl);
client.ClientCredentials.UserName.UserName = userN;
client.ClientCredentials.UserName.Password = _pasw;
client.Open();
XmlDocument soapEnvelopeXml = GetSoapString(customerId);
HttpWebRequest webRequest = CreateWebRequest(address, _action);
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
private static HttpWebRequest CreateWebRequest(string url, string action)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
}
我发送 CustomerId 的 XML:
private static XmlDocument GetSoapString(string customerId){
<urn:ZWsCustomerInvoiceGetList>
<Customerid>"+customerId+"</Customerid>
<Pedido1></Pedido1>
<Pedido2></Pedido2>
<TFacturaMat>
<item>
<Food></Food>
<Drink></Drink>
<Souvenir></Souvenir>
</item>
</TFacturaMat>
</urn:ZWsCustomerInvoiceGetList>}
我期望的 XML:
<urn:ZWsCustomerInvoiceGetList>
<Customerid>"+customerId+"</Customerid>
<Pedido1></Pedido1>
<Pedido2></Pedido2>
<rests>
<item>
<Food>Meal</Food>
<Drink>Water</Drink>
<Souvenir>Nothing</Souvenir>
</item>
</rests>
</urn:ZWsCustomerInvoiceGetList>
我的问题:
我很抱歉这么长的文字。 我无法弄清楚如何做到这一点。 是我的第一个 Web 服务,这对我来说似乎是不可能的。
SOAPAction 是端点 url。
像这样:
headers.addHeader("SOAPAction", endpointURL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.