wtorek, maja 12, 2015

How to trace .NET webrequests

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
<system.diagnostics>
        <trace autoflush="true" />
        <sources>
            <source name="System.Net" maxdatasize="1024000">
                <listeners>
                    <add name="MyTraceFile"/>
                    <add name="MyConsole"/>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add
              name="MyTraceFile"
              type="System.Diagnostics.TextWriterTraceListener"
              initializeData="System.Net.trace.log" />
                <add name="MyConsole" type="System.Diagnostics.ConsoleTraceListener" />
        </sharedListeners>
        <switches>
            <add name="System.Net" value="Verbose" />
        </switches>
    </system.diagnostics>  
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="SoapBinding">
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://eu5.salesforce.com/services/Soap/c/33.0/00000000000000001"
          binding="basicHttpBinding" bindingConfiguration="SoapBinding"
          contract="Soap" name="Soap" />
    </client>
  </system.serviceModel>
</configuration>

--
public final static void main(String[] args) throws Exception {
File f = new File("C:\\System.Net.trace.log");
BufferedReader br = new BufferedReader(new FileReader(f));
String line = br.readLine();
boolean started = false;
StringBuffer sb = new StringBuffer();
while (line!=null) {
if (line.contains("<s:Envelope")) {
started = true;
}
int idx = line.lastIndexOf(" : ");
if (idx != -1)
line = line.substring(idx + 3);
if (started) {
sb.append(line.trim());
if (sb.indexOf("</s:Envelope")!=-1) {
started = false;
System.out.println(sb.toString());
sb.setLength(0);
}
}
line = br.readLine();
}
br.close();
}
}

0 komentarze: