How to correctly call a web service in .NET

I came across a problem with calling web services that I had never heard about before. I was creating the client with a Using statement like so:

       Dim xml As XDocument = TestXml 

        Dim actual() As Byte 

        Using proxy As New MyWebService.MyServiceClient 
            actual = proxy.GenerateForm(xml.Root) 
        End Using 

This is apparently a no no, as it can mask the real error.  For me I was getting this error:

"System.ServiceModel.ChannelFactory`1[MyLibrary.PNetTServices.PNetTServicesSoap],  cannot be used for communication because it is in the Faulted state."

When in reality when I switched to the recommended client call(
       Dim xml As XDocument = MyXml 

        Dim actual() As Byte 

        Dim proxy As MyWebService.MyServiceClient = Nothing 
            proxy = New MyWebService.MyServiceClient 
            actual = proxy.GenerateForm(xml.Root) 

        Catch ex As TimeoutException 
            Throw ex 'Or do what ever 
        Catch ex As CommunicationException 
            Throw ex 
        Catch ex As Exception 
            Throw ex 
        End Try  

I got the real error message which was that in the config binding maxBufferSize cannot be a different value from maxReceivedMessageSize.


Popular posts from this blog

ToMethodObject Refactoring

How to unlock a file in Team Foundation Server(TFS)

Show/Hide formatting text in MS Word 2010