Thursday, August 28, 2014

Examining the raw data under different fault scenarios using WCF

1.       Data is requested using an ID, and is returned normally
The request:
POST http://q2testint.develop.fcbt/AbolWebService/AbolWebService.svc HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo2WwjVIEzYdEjqxDRlVRhCsAAAAAHt+W9uGBGkKFG5Y+JmYo4B63eSt8WWVMmwycwaurSYAACQAA
SOAPAction: "http://tempuri.org/IAbolWebService/GetDocumentListByAssociationFacilityControlNumbers"
Host: q2testint.develop.fcbt
Content-Length: 376
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                <s:Body>
                                <GetDocumentListByAssociationFacilityControlNumbers xmlns="http://tempuri.org/">
                                                <associationId>DATZS08</associationId>
                                                <facilityControlNumbers>00001251</facilityControlNumbers>
                                </GetDocumentListByAssociationFacilityControlNumbers>
                </s:Body>
</s:Envelope>
A soap envelope with the request data is POSTed by the client

The response when records were returned
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                <s:Body>
                                <GetDocumentListByAssociationFacilityControlNumbersResponse xmlns="http://tempuri.org/">
                                                <GetDocumentListByAssociationFacilityControlNumbersResult xmlns:a="http://schemas.datacontract.org/2004/07/Applications.Abol" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                                                                <a:Document>
                                                                                <a:DocumentFormat>pdf</a:DocumentFormat>
                                                                                <a:DocumentName>Statement - Period 05/01/2013 - 05/31/2013</a:DocumentName>
                                                                                <a:DocumentType>Statement</a:DocumentType>
                                                                                <a:DocumentUrl>http://portal- /DocIdRedir.aspx?ID=6K3XF6XK5YEP-1-6094</a:DocumentUrl>
                                                                                <a:FacilityControlNumber>00001251</a:FacilityControlNumber>
                                                                                <a:PreparedDate>2013-05-31T05:00:00Z</a:PreparedDate>
                                                                                <a:Year>2013</a:Year>
                                                                </a:Document>
                                                </GetDocumentListByAssociationFacilityControlNumbersResult>
                                </GetDocumentListByAssociationFacilityControlNumbersResponse>
                </s:Body>
</s:Envelope>
Server returns a soap envelope that contains a result element inside the response element.

The response when no records were found
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                <s:Body>
                                <GetDocumentListByAssociationFacilityControlNumbersResponse xmlns="http://tempuri.org/">
                                                <GetDocumentListByAssociationFacilityControlNumbersResult xmlns:a="http://schemas.datacontract.org/2004/07/Applications.Abol" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
                                </GetDocumentListByAssociationFacilityControlNumbersResponse>
                </s:Body>
</s:Envelope>
A soap envelope returns a response element that contains an empty result element.



The response when a system exception occurred:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="en-US">The creator of this fault did not specify a Reason.</faultstring>
      <detail>
        <CustomException xmlns="http://schemas.datacontract.org/2004/07/Services.CommonType" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <DetailExceptionMessage>Config setting missing in AbolWebService&#xD;
A request has been made to connect to XRM org for association ID:DATZS08. This failed, because the web.config file on the AbolWebService does not contain an appsetting called XRM_DATZS08. This appsetting contains the URL to the respective association's XRM org.&#xD;
</DetailExceptionMessage>
          <ExceptionMessage>A request has been made to connect to XRM org for association ID:DATZS08. This failed, because the web.config file on the AbolWebService does not contain an appsetting called XRM_DATZS08. This appsetting contains the URL to the respective association's XRM org.</ExceptionMessage>
          <InnerException/>
          <StackTrace/>
          <Title>Config setting missing in AbolWebService</Title>
        </CustomException>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

A soap envelope returns a fault element that contains a CustomException element.


Friday, June 6, 2014

Understanding wcf config files

ok - looking at this config file can be pretty confusing: this is the config file for AbolWebService.svc, which also happens to consume another service called LendingSystemService.svc.

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>

  </system.webServer>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>   
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ILendingSystemService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint
        address="http://localhost:19554/LendingSystemService.svc"
        binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_ILendingSystemService"
        contract="LendingSystemServiceReference.ILendingSystemService"
        name="BasicHttpBinding_ILendingSystemService"/>
    </client>   
  </system.serviceModel>


  1. System.WebServer - this is an instruction that defines how this as a web application behaves (no matter what the app does)
  2. System.ServiceModel - anything related to services.
    1. Behaviors - defines how services published by this application will behave. For example, this tells the service to allow other applications to discover it, and to send exception details down the wire when something goes wrong.
    2. Bindings - A list if services consumed by this application and what protocol each uses
    3. Client - a list of services that are consumed by this application: 
      1. Where the service lives
      2. Which protocol it uses