in

Paul Rausch

April 2008 - Posts

  • Overriding the default generated WSDL on a service

    I recently came across a scenario where I needed to use a flash component that consumed a web service on a project.  I had no control over the flash as it was written by a 3rd party.  Anyway the problem was the application was hosted on a load balanced configuration and when the flash would pull the WSDL definition (within the same application no less) an internal port number was appended to the service location( http://www.sitedomain.com:xxxx/app/service.asmx).   The problem was the client flash could not access that url, so what I ended up doing was overriding the wsdl generation and manually stripping out the port number.  The following code needs to be built into the web service application. Imports System
    Imports System.Web.Services.Description

    Public Class WSDLCustomGenerator Inherits SoapExtensionReflector

    Public Overrides Sub ReflectMethod()

            Dim description As ServiceDescription = ReflectionContext.ServiceDescription
           
    Dim serv As System.Web.Services.Description.Service

            For Each serv In description.Services
               
    Dim pt As Port

                For Each pt In serv.Ports
                     Dim ext As ServiceDescriptionFormatExtension 
                     
                     For Each ext In pt.Extensions
                         
    Dim binding As SoapAddressBinding
                          binding = CType(ext, SoapAddressBinding)

                          If Not binding Is Nothing Then
                              'Nice hacky way of testing for the :xxxx port after the url I'm assuming is 10 characters long, and shouldn't have a port number ever
                             
    If binding.Location.IndexOf(":", 10) > 0 Then

                             'Replace port number
                             binding.Location = binding.Location.Remove(binding.Location.IndexOf(":", 10), 5)

                         End If
                    
    End If
                  
    Next
              
    Next
           
    Next
    End Sub
    End Class

  • Sorting Collections

    With the new language features in the .Net framework this has become much simpler.  I had to implement sorting on a custom collection in two projects last week, one being .net 1.1 and one being .net 3.5.  Let me tell you it was much easier in 3.5 and much more flexible as you can order by multiple fields without doing multiple IComparers.

    In .net 1.1 I had to implement a custom IComparer class to do the comparison, which involves creating a whole new class and adding logic to do the sorting.

    In .net 3.5 all I had to do was this:

    myCollection = myCollection.OrderBy(obj => obj.FieldToSort).ToList()

    or

    myCollection  = (from obj in myCollection orderby obj.FieldOne, obj.FieldTwo select obj).ToList()

  • Disabling a CRM User service error

    I recently had a problem where a user account on our test CRM installation was disabled without my knowledge.  The problem is I started getting authentication errors updating any records through CRM web services that had that user as the owner.  I could logon to CRM itself with the same credentials being used to call the web services and update record with that same disabled user as the owner, it would only cause problems udpating through the web services.  The error messages was just the generic authentication error which didn't help much.  So moral of the story is if you disable a user account change ownership to an active user on CRM entities.

    PS - What I had to do to figure it out since I didn't know that user had been disabled is take a record that worked and one that didn't and go field by field in the database to figure out what was different.

    Posted Apr 02 2008, 10:11 AM by prausch with no comments
    Filed under:
  • Close an Opportunity in CRM 3.0 via web services

    It took me a little time to figure out how set the state/status of a Opportunity to a win.  Other times I've had to set states/status on a CRM object I've only had to use the corresponding SetStateRequest object which does exist for Opportunity but fails to do what I needed.  The following code shows how to close an Opportunity.  I apologize its in VB.

    CRMService is the web reference to the CRM service URL.

    Dim oppClose As CRMService.opportunityclose = New CRMService.opportunityclose
    oppClose.opportunityid =
    New CRMService.Lookup
    oppClose.opportunityid.type = CRMService.EntityName.opportunity.ToString()
    oppClose.opportunityid.Value = opportunity.opportunityid.Value

    'Set fields related to the win
    oppClose.actualrevenue = CrmTypes.CreateCrmMoney(0)
    oppClose.actualend = CrmTypes.CreateCrmDateTime(DateTime.Today.ToShortDateString())

    Dim woReq As CRMService.WinOpportunityRequest = New CRMService.WinOpportunityRequest
    woReq.OpportunityClose = oppClose
    woReq.Status = 3

    Dim service As CRMService.CrmService = CrmServiceManager.GetService() 'Custom service reference factory
    Dim woResp As CRMService.WinOpportunityResponse = CType(service.Execute(close), CRMService.WinOpportunityResponse)

  • Rich Text Editing Made Easy

    I came across a new rich text editor in a project recently where I just needed some simple lists/bolding/color capabilities.  Its super easy to use, you just reference the .dll and add it like any other server control to your page.  The nice part is everything is compiled into the .dll, you don't have to add images or scripts to your project to support actions or tool bars.  I didn't get into the adding of images or the more complex stuff though.  You can also specify the tool bar look and feel from a few different office type looks.  Oh, and its cheap!

    Anyway, here is the link.

    http://freetextbox.com/default.aspx

Inetium, LLC. Disclaimer