Link to home
Start Free TrialLog in
Avatar of metlogistics
metlogistics

asked on

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
       
   
Avatar of daveamour
daveamour
Flag of United Kingdom of Great Britain and Northern Ireland image

Could be some kind of security issue - firewall for example?
Can you browse to the web service through IE and use it that way?
Avatar of metlogistics
metlogistics

ASKER

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.
Is the web server outside of your network - ie out on the internet or is it an internal web server?
its on internet...can accessed from outsite.
Is it something I can try?
Ok will give it and go and try and reproduce your problem.
Just off home now but will try later on.
 
ok..you can use ProductID = 1-5 and quantity from 1-10 to test..thank you...
Oh also which web server OS are you using too?
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?
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/
Also show some code from your webservice so we know exactly the format of the xml that is being emitted.
The web service works perfect  through the VS2008 own web server.
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

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).
I see that the return from the web method does not include the xml declaration:

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

how would I fix that? thanx
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 ---
ASKER CERTIFIED SOLUTION
Avatar of nmarun
nmarun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..