Getting raw soap errors?

Hi there,

Ive been asked to send back the raw soap I am getting from the adcenter API. Im using VS 2005......is there an easy way of doing this? When I catch the exception as a SOAPexception I cant find a property to access the XML that was received from the server?

Cheers,

Justin.

[307 byte] By [Justin-M] at [2008-2-11]
# 1

Hopefully this sample will help:

Using the .NET XmlSerializer class, you can capture the method parameters for the methods that your application sends to the adCenter web services, and also capture the return values sent to your application from the adCenter web services.

The XmlSerializer class allows you to save entities in XML format. While this is not the same as saving entities in SOAP format, you may find the XML format suitable for debugging purposes.

Note
If you capture your credentials, such as user name, password, and user access key, in SOAP or XML, ensure that you do not disclose them.

The following C# code shows how to serialize a report request variable after it has been prepared for a call to Reporting.RequestBIReport.

using System;

using System.IO;

using System.Xml.Serialization;

using ReportV3AccountPerformanceReportRequest.ReportingV3;

namespace ReportV3AccountPerformanceReportRequest

{

class Program

{

static void Main(string[] args)

{

// Some of this code would appear in a

// typical report request application. It could

// be removed if you only want to capture the

// report request variable.

// Reporting web service and auth header variables.

Reporting objReport;

ApiUserAuthHeader apiUserAuthHdr;

// Serialization and file variables

XmlSerializer xmlSerial;

Stream stream;

// Create the web service object.

objReport = new Reporting();

// Create the auth header and assign values.

apiUserAuthHdr = new ApiUserAuthHeader();

apiUserAuthHdr.UserName = "******"; // Use your values.

apiUserAuthHdr.Password = "******"; // Use your values.

apiUserAuthHdr.UserAccessKey = "******"; // Use your values.

// Assign the auth header to the web service member.

objReport.ApiUserAuthHeaderValue = apiUserAuthHdr;

// Create a report request.

AccountPerformanceReportRequest acctPerfReportRequest;

acctPerfReportRequest = new AccountPerformanceReportRequest();

// Assign values to the report request variable.

// Account ID is application specific, and is

// retrieved by a call to CustomerManagement.GetAccounts.

acctPerfReportRequest.AccountId = 489;

acctPerfReportRequest.AllNone = false;

acctPerfReportRequest.ReportLanguage = ReportLanguageType.English;

acctPerfReportRequest.Format = APIResultFileType.XML;

acctPerfReportRequest.ReportDateRange = ReportDateRangeType.Last6Months;

// Serialize the report request parameter to a file.

xmlSerial = new XmlSerializer(acctPerfReportRequest.GetType());

stream = new FileStream(@"c:\mysoap\ReportRequest.xml",

FileMode.Create,

FileAccess.Write,

FileShare.None);

xmlSerial.Serialize(stream, acctPerfReportRequest);

stream.Close();

// Your report request variable has now been serialized to

// to the file specified above.

// Remaining code not shown.

}

}

}

For brevity, the call to RequestBIReport was not shown, but the code above captures the report request prior to its intended use. The following shows the serialized output capture by the code above.

<?xml version="1.0"?>

<AccountPerformanceReportRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<StartDate xsi:nil="true" xmlns="http://adcenter.microsoft.com/syncapis" />

<EndDate xsi:nil="true" xmlns="http://adcenter.microsoft.com/syncapis" />

<ReportLanguage xmlns="http://adcenter.microsoft.com/syncapis">English</ReportLanguage>

<Format xmlns="http://adcenter.microsoft.com/syncapis">XML</Format>

<AllNone xmlns="http://adcenter.microsoft.com/syncapis">false</AllNone>

<ReportDateRange xmlns="http://adcenter.microsoft.com/syncapis">Last6Months</ReportDateRange>

<ReportAggregation xsi:nil="true" xmlns="http://adcenter.microsoft.com/syncapis" />

<AccountId xmlns="http://adcenter.microsoft.com/syncapis">489</AccountId>

</AccountPerformanceReportRequest>

You can see for example that the value of 489 is specified in the <AccountId> element. This value was set for the AdPerformanceReportRequest.AccountId Property in the C# code above.

A similar technique can be used to capture the return values from an adCenter web service. After the return value is sent to your application, you can use the same serialization technique shown above to save the result to disk.

Consult the .NET Framework documentation for more information about the XmlSerializer class.

ShaiKariv-MSFT at 2007-9-3 > top of Msdn Tech,Windows Live Developer Forums,Microsoft adCenter: Development...

Windows Live Developer Forums

Site Classified