SOAP object over HTTP post in C# .NET

前端 未结 2 1199
心在旅途
心在旅途 2021-02-08 01:56

I am trying to compose a SOAP message(including header) in C# .NET to send to a URL using HTTP post. The URL I want to send it to is not a web-service, it just receives SOAP mes

2条回答
  •  时光取名叫无心
    2021-02-08 02:20

    your code above was missing a parenthesis and had an extra comma, i fixed it here:

    XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/"; 
    var document = new XDocument( 
        new XDeclaration("1.0", "utf-8", String.Empty), 
        new XElement(soapenv + "Envelope", 
            new XAttribute(XNamespace.Xmlns + "soapenv", soapenv), 
            new XElement(soapenv + "Header", 
                new XElement(soapenv + "AnyOptionalHeader", 
                    new XAttribute("AnyOptionalAttribute", "false")
                ) 
            ), 
            new XElement(soapenv + "Body", 
                new XElement(soapenv + "MyMethodName", 
                    new XAttribute("AnyAttributeOrElement", "Whatever") 
                ) 
            ) 
        )
    ); 
    

提交回复
热议问题