[英]I don't know how to do a Soap Request using C# ASP.NET
I've been trying for hours to do a Request to my Soap Client (SoapUI), reading documentation or recycling code (Yes, sorry), but I am unable to do a simple request.我已经尝试了几个小时向我的 Soap 客户端 (SoapUI) 发出请求,阅读文档或回收代码(是的,抱歉),但我无法发出简单的请求。
What I'm trying to do is simple:我想做的很简单:
That's all.就这样。
Some code:一些代码:
//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);
}
}
XML where I send the CustomerId:我发送 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 that I expect:我期望的 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>
My problems:我的问题:
I'm sorry for all this long text.我很抱歉这么长的文字。 I can't figure it out how to do this.
我无法弄清楚如何做到这一点。 Is my first Web Service and it seems impossible for me.
是我的第一个 Web 服务,这对我来说似乎是不可能的。
SOAPAction is the endpoint url. SOAPAction 是端点 url。
Like this:像这样:
headers.addHeader("SOAPAction", endpointURL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.