SOAP 1.2 POST request working in Postman, not working in local Visual Studio solution—"Data at the root level is invalid"

Viewed 880

I have a Postman request that spits out the following code:

using System;
using RestSharp;
namespace HelloWorldApplication {
  class HelloWorld {
    static void Main(string[] args) {
      var client = new RestClient("https://test-ewebservice.it.abc.com/CentralPaymentSite_WS/service.asmx?op=AuthCapRequestWithAddressAndName");
      client.Timeout = -1;
      var request = new RestRequest(Method.POST);
      request.AddHeader("Content-Type", "application/soap+xml; charset=utf-8");
      request.AddHeader("Cookie", "BIGipServer~UISS~test-ewebservice.it.abc.com_443_pool=2697198090.47873.0000");
      request.AddParameter("application/soap+xml; charset=utf-8", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n  <soap12:Body>\n    <AuthCapRequestWithAddressAndName xmlns=\"webservice.it.abc.com\">\n      <MerchantID>AbcId</MerchantID>\n      <AuthorizationAmount>10.00</AuthorizationAmount>\n      <OneStepTranType>string</OneStepTranType>\n      <ApplicationIDPrimary>string</ApplicationIDPrimary>\n      <ReturnURL>http://nopcommerce.test/foo</ReturnURL>\n      <AuthorizationAttemptLimit>1</AuthorizationAttemptLimit>\n      <ApplicationIDSecondary>string</ApplicationIDSecondary>\n      <ApplicationStateData>string</ApplicationStateData>\n      <StyleSheetKey>string</StyleSheetKey>\n      <EmailAddressDeptContact>string</EmailAddressDeptContact>\n      <BillingAddress>string</BillingAddress>\n      <BillingCity>string</BillingCity>\n      <BillingState>string</BillingState>\n      <BillingZipCode>string</BillingZipCode>\n      <BillingCountry>string</BillingCountry>\n      <PostBackURL>http://nopcommerce.test/foo</PostBackURL>\n    </AuthCapRequestWithAddressAndName>\n  </soap12:Body>\n</soap12:Envelope>",  ParameterType.RequestBody);
      IRestResponse response = client.Execute(request);
      Console.WriteLine(response.Content);
    }
  }
}

When I run my Postman request, I get the expected successful response. When I run the code in my VS solution, I get the following error:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

What am I doing wrong?

0 Answers
Related