[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

Web Service not working in Production Server

I am trying to consume a web service using asp.net 2.0 and everything works fine through the VS2008 server (when I test the application) but when I move it to the production server, it doesnt recognize the web service class.
I am adding the web reference by pointing to the web service on the web, and creating the app_webreferences folder with all the required files.
Is this an IIS or web.config issue ? Page code below.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ProductID As Integer
        Dim Quantity As Integer
        Dim Quote_Number As Integer
       
        ProductID = lst_Products.SelectedValue
        Quantity = lst_Quantity.SelectedValue

       ***** Getting Error at this line *******  Dim ShipperWebService As New Quote.WebService
       
        Quote_Number = ShipperWebService.ReceiveQuoteRequest(ProductID, Quantity)
       
        If Quote_Number > 0 Then
           
            Label1.Text = "We have received your request. Your quote number is " & Quote_Number & ". Please use this for future reference"
        End If
       
   
0
metlogistics
Asked:
metlogistics
  • 10
  • 5
  • 5
1 Solution
 
daveamourCommented:
Could be some kind of security issue - firewall for example?
Can you browse to the web service through IE and use it that way?
0
 
metlogisticsAuthor Commented:
Yes, the web service works fine if I invoke it thorugh the browser. The webservice is on a web server and my local asp.net page connects to it fine when its under VS2008. On the same Local computer, when I copy the site to the webroot folder, it doesnt recognize the web service class.
0
 
daveamourCommented:
Is the web server outside of your network - ie out on the internet or is it an internal web server?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
metlogisticsAuthor Commented:
its on internet...can accessed from outsite.
0
 
daveamourCommented:
Is it something I can try?
0
 
metlogisticsAuthor Commented:
0
 
daveamourCommented:
Ok will give it and go and try and reproduce your problem.
Just off home now but will try later on.
 
0
 
metlogisticsAuthor Commented:
ok..you can use ProductID = 1-5 and quantity from 1-10 to test..thank you...
0
 
daveamourCommented:
Oh also which web server OS are you using too?
0
 
metlogisticsAuthor Commented:
web server OS is 2000. My local computer is Windows 2008. I get the error when I put the files on either servers. It only works within the visual studio 2008, I am suspecting a namespace or reference issue?
0
 
nmarunCommented:
Use Fiddler2 to check if the webservice is getting called properly. There's also a small video that shows you how to use the tool: http://www.fiddler2.com/fiddler2/
0
 
nmarunCommented:
Also show some code from your webservice so we know exactly the format of the xml that is being emitted.
0
 
metlogisticsAuthor Commented:
The web service works perfect  through the VS2008 own web server.
0
 
metlogisticsAuthor Commented:
plz see attached..
<%@ WebService Language="VB" Class="WebService" %>
 
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
 
 
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace := "http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _  
Public Class WebService
    Inherits System.Web.Services.WebService 
    
    <WebMethod()> _
    Public Function ReceiveQuoteRequest(ByVal ProductID As Integer, ByVal Quantity As Integer) As String
        Dim Quote_Number As Integer
        Quote_Number = CreateQuote(ProductID, Quantity)
        Return Quote_Number
    End Function
    
    
    Public Function SendQuoteTotal(ByVal QuoteID As Integer) As Integer
        
        Dim Total As Integer
        
        Dim DBConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ECT481").ConnectionString)
        Dim Command As SqlCommand
        Dim DataReader As SqlDataReader
        
       
 
        Command = New SqlCommand("GetQuote", DBConnection)
        Command.CommandType = CommandType.StoredProcedure
        Command.Parameters.AddWithValue("@QuoteID", QuoteID)
 
        DBConnection.Open()
        DataReader = Command.ExecuteReader()
 
 
        If DataReader.HasRows Then
 
            While DataReader.Read
 
                Total = DataReader("Total")
               
               
            End While
        
        Else
            Total = 0
        End If
 
        
        
        DBConnection.Close()
        
        Return Total
    End Function
    
    
    
    
    'Function to Create Quote
    Private Function CreateQuote(ByVal ProductID As Integer, ByVal Quantity As Integer) As String
    
        Dim DBConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ECT481").ConnectionString)
        
        Dim Quote_Number As Integer
        Dim Product_Cost As Integer = GetProductCost(ProductID)
        Dim Total As Integer = Quantity * Product_Cost
        
        
        Dim Command As SqlCommand = New SqlCommand("Create_Quote", DBConnection)
        Command.CommandType = CommandType.StoredProcedure
 
        Command.Parameters.AddWithValue("@Product_ID", ProductID)
        Command.Parameters.AddWithValue("@Total", Total)
        
 
        Command.Parameters.Add(New SqlParameter("@Quote_Number", Data.SqlDbType.Int, 4))
        Command.Parameters("@Quote_Number").Direction = ParameterDirection.Output
 
        DBConnection.Open()
        Command.ExecuteNonQuery()
 
        Quote_Number = Command.Parameters.Item("@Quote_Number").Value
        DBConnection.Close()
 
        
        Return Quote_Number
    End Function
    
        
    'Function to get Product Cost by Product ID
    Private Function GetProductCost(ByVal ProductID As Integer) As Integer
    
        Dim DBConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ECT481").ConnectionString)
        Dim Command As SqlCommand
        Dim DataReader As SqlDataReader
        
        Dim Product_Cost As Integer
 
        Command = New SqlCommand("GetProductCost", DBConnection)
        Command.CommandType = CommandType.StoredProcedure
        Command.Parameters.AddWithValue("@ProductID", ProductID)
 
        DBConnection.Open()
        DataReader = Command.ExecuteReader()
 
 
        If DataReader.HasRows Then
 
            While DataReader.Read
 
                Product_Cost = DataReader("Price")
               
            End While
        End If
 
        DBConnection.Close()
        
        Return Product_Cost
        
        
    End Function
        
End Class

Open in new window

0
 
nmarunCommented:
Yep, I read that part earlier, Fiddler2 shows you http traffic, so when you're doing your test on the production site you can see if the webservice is being called correctly and if the result that it returned successfully (http status 200).
0
 
nmarunCommented:
I see that the return from the web method does not include the xml declaration:

<?xml version="1.0" encoding="utf-8" ?>

0
 
metlogisticsAuthor Commented:
how would I fix that? thanx
0
 
metlogisticsAuthor Commented:
thanx every, I solved the first problem by moving the whole application to a new website and now it works. However, Now when consuming the web service, I get this error:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at WebService.CreateQuote(Int32 ProductID, Int32 Quantity) in C:\Inetpub\METLogistics.com\ECT481\shipper_webservice.asmx:line 70
  at WebService.ReceiveQuoteRequest(Int32 ProductID, Int32 Quantity) in C:\Inetpub\METLogistics.com\ECT481\shipper_webservice.asmx:line 21
  --- End of inner exception stack trace ---
0
 
nmarunCommented:
Did you make sure the connection string

ConfigurationManager.ConnectionStrings("ECT481").ConnectionString

is actually returning a value? In other words, does the web.config file have the connection defined?

If not, see what is there in line 70 inside the CreateQuote method.
0
 
metlogisticsAuthor Commented:
Yes, I got excited and started cleaning code and accidently deleted that connection string.

The web service was fine, the problem was with my IIS. After creating a new website and giving proper rights, I am able to make everything work..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now