Is it possible to output the SOAP message from a formed PIArcDataRequest?
I'm working on a test tool for configuring PI Web Services and would like to write the SOAP message to a text box on the tool.
Please take a look on the example below:
public void MethodGetPIArchiveData()
string path = @"pi\\marc-pi2014\sinusoid";
string starttime = "*-2d";
string endtime = "*";
TimeRange timeRange = new TimeRange();
timeRange.Start = starttime;
timeRange.End = endtime;
PIArcManner manner = new PIArcManner();
manner.Boundaries = PIArcMannerBoundaries.Inside;
manner.RetrievalType = PIArcMannerRetrievalType.Compressed;
PIArcDataRequest request = new PIArcDataRequest();
request.PIArcManner = manner;
request.TimeRange = timeRange;
request.Path = path;
List<PIArcDataRequest> requests = new List<PIArcDataRequest>();
List<TimeSeries> results = ptsc.GetPIArchiveData(requests.ToArray()).ToList();
foreach (TimeSeries result in results)
foreach (TimedValue value in result.TimedValues)
value.Path ?? result.Path
, value.UOM ?? result.UOM);
If you want to display the results on a text box use the function TextBox.Text = value.Value instead of using Console.WriteLine(). Did I answer your question?
Thanks Marcos, but I already have that part. What I am looking for is the SOAP message that is formed by the application and sent via POST to the web site. The purpose of the utility tool is to aid in discovering what went wrong when it doesn't work.
It might look something like this:
I realize that the formatting may not be as nice, but I would like to see what my application is sending to the PI Web Service.
@David: I would suggest that you use Fiddler to intercept the formed message. As an example, a GetPIArchiveData call would look like the following.
<soapenv:Envelope xmlns:soapenv=`"http://schemas.xmlsoap.org/soap/envelope/`" xmlns:pid=`"http://xml.osisoft.com/services/PIDataService`">
It will be possible only if you are not using transport encryption.
May I ask what you are trying to achieve here? Is it a test tool that would form SOAP messages for you?
You can also retrieve the raw data within a WCF context by writing a message inspector:
This will work in a scenario where you're using transport layer security. But when using message layer security, as in the PI WS default config, you'll actually see the encrypted payload in the SOAP message.
The tool is intended to be used to troubleshoot a connection to a PI-Web Service. It does not manually form SOAP messages. I am using a simple Windows Forms application in C# with the PITimeSeriesService.cs generated by svcutil.exe as indicated by the wsdl post to the service.
Getting the configuration right where you are trying to use certificate authentication of external entities connecting to your PI system can be challenging.
We also have a customer who is having difficulty with their application which connects to our PI-Web service, particularly with the date format being sent out in the SOAP message. Since my application works I would like to see what SOAP message is being formed by the application.
The Message Inspectors setup is very complicated to set up. I did get the eight additional classes created (would have been a few more if I and included the ability to inspect the service as well as the client). It would probably have been better if I had setup all of the WCF Samples first but it took long enough as it was to set this up. (There was a lot left to the imagination.)
Have you ever used this? I am at the point that I need to have my SchemaValidationBehaviorExtensionElement registered to reference it in the behaviorExtensions of my configuration file. Do you have any guidance on how to do this? Can it be configured as part of a VS2008 setup project? I know this is beyond this forum in some respects, but you brought up the suggestion.
The most reliable date format to use with PI Web Services is an ISO 8601 DateTime:
Another option is to turn on WCF tracing on the PI Web Services server side. The appropriate section exist, but are commented out, in the PIWebServices.config file. This MSDN article contains more information:
Have you ever used MessageInspector? It is a huge PITA to set up. Lot's of bad code in the MS sample code. Not huge things, just lots of little things. Enough to drive you crazy. I don't want to set up the WCF Samples because that, in itself, will be another huge undertaking.
Is the message.xsd a schema for the SOAP message you are trying to read?
Is is possible that OSI will share the schema they used to create SOAP messages for PI Web Services?
Anything you have learned from running this would be helpful.
Incidentally, I have turned on tracing and extra logging. They don't help with the SOAP message. They do help with other things though.
I still can't seem to get IIS to map a certificate to an AD user. I am looking to see that the SOAP message contains the reference to or BLOB of the certificate I am trying to get mapped.
I have written a MessageInspector before, and what I remember most is that when you're inspecting the message, you have to first make a copy of it, because it's a once-and-done (derp).
If you're just looking to inspect the payload for troubleshooting purposes, though, MessageInspector is overkill. I'm really surprised that the WCF Message Log isn't working for you. Can I kindly suggest that you call Tech Support and work with them to get the payload of requests/responses writing to the WCF message log? I have used this many, many times during PI Web Services development to see the contents of incoming requests and outgoing responses.
The WCF Message Log does work it just doesn't provide the information I am looking for. It may be that I could configure it to include this information. I don't know. I am trying to configure PI Web services to support SSL security with Client Certificate mapping so several external entities could use the same web site to pull data from PI and each entity would be identified, mapped to a PI Identity and given access only to the appropriate tags.
I have a certificate which is bound to the web site for the SSL binding which appears to work. I have a certificate for the user which is installed on the users workstation in the cert store, LocalMachine. The client certificate is also configured on the IIS server and mapped to a domain user complete with the users password in the iisClientCertificateMappingAuthentication section of ApplicationHost.config.
I have the SSL settings set to require SSL and require Client certificates.
I have an application I built to pull data from the PI Web services which runs on the users workstation and I do get data. But when I check the PI-SMT Network Manager I see that the OS User is the Application pool user that is configured for the site and not the domain user that the client's certificate should map to.
All I get for a log message from WCF Message log is:
#Software: Microsoft Internet Information Services 7.5
#Date: 2014-02-12 17:54:34
#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
2014-02-12 17:54:34 W3SVC1 xxx.xxx.xxx.89 POST /PITimeSeries.svc - 443 - xxx.xxx.xxx.111 - 200 0 0 4234
Note that I x-ed out the first three octets of the IP. But there is no indication of the user's certificate. this doesn't even include the call to PI Web services i.e. the tag-path, dates or mannor. They aren't particularly important here, but might be in a different situation.
My application code gets the client credentials as follows:
client = new PITimeSeriesClient();
ClientCredentials clientCred = client.ClientCredentials;
if (clientCred.ClientCertificate.Certificate != null)
output.AppendLine("Certificate FN=" +
output.AppendLine("Certificate SerNo=" +
and writes it to a status log on the application as follows:
Certificate FN=service wsmcgeas's COMODO CA Limited ID
This matches the information supplied in the application config file. The call is for GetPISnapshotData so there is no date or mannor. I have verified that the certificate serial number matches the one I am sending. But I have no indication that what I see from my application is actually being sent to the server. And I don't get client certificate mapping. Hince, the desire to see the SOAP message.
That looks like an IIS log file-- it's definitely not a WCF message log, which is XML format, usually has the extension .svclog, and can be opened with the WCF Service Log Viewer tool.
There are two blocks to uncomment in PIWebServices.config to enable WCF message logging. The first starts like this:
<!-- Uncomment this section and the one in system.serviceModel to enable WCF diagnostics
And the second looks like this:
<!-- Uncomment this section and the system.diagnostics section above to enable WCF diagnostics
<diagnostics wmiProviderEnabled="true" performanceCounters="Default">
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
In the first section, you'll likely want to change the "initializeData" attribute to a path that is writable by your process account (by default, Network Service). Once that configuration is set, you should see PI Web Services begin to populate the specified files when a request is received.
You could also do all of this on the client side, but it's likely easier on the server side given that the necessary configuration blocks are already there in the right places, just commented out.
Thanks Brad. I had un-commented the diagnostic sections, but I didn't know where they were writing. This solves my problem of wanting to see the SOAP message. But, from what I see, there is no indication that the credentials are getting passed to the IIS server.
Retrieving data ...