Web Services: SoapException was Unhandled by User

Posted on 2011-09-08
Last Modified: 2012-05-12

I created a web service
This has one method with a parameter and returns a value.

String fare= GetFare(ClientID)

When i run the service, it works good. No issues.
I deployed it to my local server(LocalA). The database is at a remote server(RemoteA).

When i try to consume it from a client, after deploying on a server, i am getting Soap Exception was unhandled by user code.
Server was unable to process request.

Attaching my code below:


<WebMethod()> _
    Public Function GetFare(ByVal clntid As String) As String
        Dim tripfr As String = Nothing
        Dim constring As String = Nothing
        constring = System.Configuration.ConfigurationManager.ConnectionStrings("WS").ConnectionString.ToString

        Dim mycon As New SqlConnection(constring)

        Dim strquery As String = Nothing
        strquery = "select fare from schedules  where clntid = '" & clntid & "'"
            Dim mycmd As New SqlCommand(strquery, mycon)
            Dim myreader As SqlDataReader = Nothing
            myreader = mycmd.ExecuteReader()

            While myreader.Read
                tripnm = myreader.Item(0)
            End While
        Catch soapex As SoapException

        End Try

        Return tripfr 

    End Function

Client Application to Consume:

Private Sub Sh_Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sh_Button1.Click

        Dim callService As New MDC.myMDCService

        Dim tripfr As String = Nothing
        tripfr = callService.GetRecord(textbox1.Text) /////// -- Error Here.


    End Sub

Open in new window

Question by:shahjagat
  • 5
  • 3
  • 2
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36506745
CatchCatch soapex As SoapException

Open in new window

That line of code isn't going to do you any good because your service code isn't the layer that's raising the SOAP excpetion--it's an underlying layer in the runtime. Most likely, you've got an exception dealing with SQL Server, so I'd suggest changing SoapException to SqlException. Also, you would want to catch a SoapException in your client code, not the server code.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36506753
In code, the last sentence in my previous comment would be:
    tripfr = callService.GetRecord(textbox1.Text)
Catch soapex As SoapException
    Console.WriteLine(soapex.ToString())  ' For example
End Try

Open in new window


Expert Comment

by:Grant Spiteri
ID: 36506818
Ok few questions:

1. The server where the Application resides (Client), is this on a different domain / server to the actual service?
2. What type of authentication is set on both the service and application?
3. Have you created specific users for the app pools that both the application & service reside?
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 36506886
Hi Kaufmed,

This is my error message: Do you tthink some thing wrong with connection to sql server?

Server was unable to process request. ---> A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.)

Author Comment

ID: 36506898

Server where Web service is hosted is in our office in our network.
Database Server is locatesd at a remote location on a different network  They are on different domains.

Not sure about ur questions 2 and 3.
I did not create anything else at all.


Accepted Solution

Grant Spiteri earned 125 total points
ID: 36507300
is your service set up in IIS with windows authentication only etc...

Im running windows 7 so im just going off my iis manager:

Question 2: if you go to IIS Manager select your service and under the security section double click on authentiction to aquire what i need to know

Question 3: stay in the iis manager right click on the service and select manage application and the select advance, take note of the value next to the application pool option. Then close out of that and select application pools under the top level of the tree in the manager on the left, right click on the app pool from the service click advance settings, then under process model next to option identity is it a custom username or simply ApplicationPoolIdentity

also i would just double check permissions on the db for the user assigned to the connection string in your config
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 125 total points
ID: 36507387
Make sure your connection string to your database is configured properly as well  = )

Author Comment

ID: 36512210
Hi gspiteri and kaufmed,

I think the issue was with the sql server on our server. It was not seeing/communicating with the external server.
When this part worked, web service worked.

Giving points to both.


Author Closing Comment

ID: 36512216

Author Comment

ID: 36512221
Edit: Issue was with the local server where the web service was deployed. (not sql server as mentioned)
When we restarted  the server it worked.

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question