Solved

Web Services: SoapException was Unhandled by User

Posted on 2011-09-08
10
2,604 Views
Last Modified: 2012-05-12
Hi,

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:


Thanks




<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 & "'"
        Try
            mycon.Open()
            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
         
        Finally

        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.


        MessageBox.Show(tripfr)

    End Sub

Open in new window

0
Comment
Question by:shahjagat
  • 5
  • 3
  • 2
10 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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.
0
 
LVL 74

Expert Comment

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

Open in new window

0
 
LVL 9

Expert Comment

by:Grant Spiteri
Comment Utility
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?
0
 

Author Comment

by:shahjagat
Comment Utility
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.)
0
 

Author Comment

by:shahjagat
Comment Utility
gspiteri,

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.

thanks
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 9

Accepted Solution

by:
Grant Spiteri earned 125 total points
Comment Utility
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
0
 
LVL 74

Assisted Solution

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

Author Comment

by:shahjagat
Comment Utility
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.

Thanks
0
 

Author Closing Comment

by:shahjagat
Comment Utility
Thanks
0
 

Author Comment

by:shahjagat
Comment Utility
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now