简体   繁体   English

我不知道如何使用 C# ASP.NET 进行 Soap 请求

[英]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:我想做的很简单:

  • The User inserts a CustomerId and a mail用户插入 CustomerId 和邮件
  • The CustomerId goes to my HomeController CustomerId 转到我的 HomeController
  • HomeController do a Request to the Soap Client HomeController 向 Soap 客户端发出请求
  • The User receives a PDF file to the mail with more information.用户通过邮件收到包含更多信息的 PDF 文件。

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 don´t understand what goes in "action" parameter in CreateWebRequest我不明白 CreateWebRequest 中的“action”参数中的内容
  • System.Xml.XmlException: ''http' is an unexpected token. System.Xml.XmlException: ''http' 是一个意外的标记。 The expected token is '"' or '''. Line 1, position 33.'预期的标记是 '"' 或 '''。第 1 行,位置 33。' in GetSoapString在 GetSoapString 中
  • I don't know how to use the references that Visual Studio provides me in Reference.cs.我不知道如何使用 Visual Studio 在 Reference.cs 中为我提供的引用。

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.

相关问题 刚开始学习 C# &amp; ASP.NET - 奇怪的语法(对我来说),我不知道它是什么 - Just started learning C# & ASP.NET - strange syntax (to me) and I don't know what it is 我在c#中使用html代码和css设计按钮,并且单击它后我不知道如何将其重定向到另一个页面(ASP.net) - Im using html code and css in c# to design the button and i don't know how to redirect it to another page after clicked it(ASP.net) 如何使用ASP.Net/ C#请求服务器时间 - How do I request server time using ASP.Net/ C# 我如何使用ASP.NET C#中的客户端证书访问Soap Web服务 - How Can i access soap webservice using Client certificates in asp.net c# ASP.net C#,我怎么知道使用什么? - ASP.net c#, how do I know what to use? 如果我不知道GUID,如何使用c#在Microsoft CRM上检索一条记录? - How do I retrieve a single record on Microsoft CRM using c# if I don't know the GUID? 如何查看通过网络发送的C#ASP.NET应用发送的SOAP请求数据? - How to see SOAP request data sent by C# ASP.NET app that gets sent over network? C# ASP.NET MVC:如何限制通过 POST 请求传入的字符数? - C# ASP.NET MVC : how do I limit the number of characters passed in through a POST request? 使用c#/ ASP.NET添加自定义SOAP标头 - Adding a custom SOAP header using c#/ASP.NET 我不知道如何在asp.net中使用命令参数 - i don't know how to work with command argument in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM