views:

78

answers:

2

I'm getting a failure in my web application calling a webservice:

Server Error in '/zVersion2a' Application. The request failed with HTTP status 400: Bad Request.

Here is a link to the webservice itself (this works):

http://www.zipeee.com/Zipeeewebservice/

Here is a link to the [production] web app that calls the WS on the first page load:

http://www.zipeee.com/Zipeee/

Here is a link to the [newVersion] web app that fails calling this same WS:

http://www.zipeee.com/zVersion2/

Here is the source in the calling page:

Imports System.Data
Partial Class frmZipeee
Inherits System.Web.UI.Page
Public wsZipeee As New ProxyZipeeeService.WSZipeee.Zipeee
Dim dsStandardMsg As DataSet
Dim dtStandardMsg As DataTable
Dim dsRandomMsg As DataSet
Dim dtRandomMsg As DataTable
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not Page.IsPostBack Then
        LoadMessage()
    End If
End Sub
Private Sub LoadMessage()
    Dim iCnt As Integer
    Dim iValue As Integer

    dsStandardMsg = Nothing
    dsStandardMsg = wsZipeee.GetMessageByType(BizConstants.MsgType.Standard)
    iCnt = dsStandardMsg.Tables(0).Rows.Count
        If iCnt = 0 Then
            Me.btnEnter.Text = "Click Here to Enter."
        Else
            Me.btnEnter.Text = dsStandardMsg.Tables(0).Rows(0).Item("MessageContent")
        End If
    dsStandardMsg.Dispose()
End Sub
End Class

Here is the code from Reference.vb in the proxy:

<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ZipeeeWebService/Zipeee/Get Message By Type", RequestElementName:="Get Message By Type", RequestNamespace:="http://tempuri.org/ZipeeeWebService/Zipeee", ResponseElementName:="Get Message By TypeResponse", ResponseNamespace:="http://tempuri.org/ZipeeeWebService/Zipeee", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _
    Public Function GetMessageByType(ByVal iMsgType As Integer) As <System.Xml.Serialization.XmlElementAttribute("Get Message By TypeResult")> System.Data.DataSet
        Dim results() As Object = Me.Invoke("GetMessageByType", New Object() {iMsgType})
        Return CType(results(0),System.Data.DataSet)
    End Function

Finally, here is the code in the webservice:

   <WebMethod(MessageName:="Get Message By Type")> _
           Public Function GetMessageByType(ByVal iMsgType As Integer) As DataSet
    Try
        'create a connection...
        con = New SqlConnection(sConnZipeee)
        con.Open()
        command = New SqlCommand("spGetMessageByType", con)
        command.CommandType = CommandType.StoredProcedure
        AppendParm(command, "@MessageType", SqlDbType.Int, iMsgType)
        Dim adp As SqlDataAdapter = New SqlDataAdapter(command)
        Dim ds As New DataSet
        adp.Fill(ds, "TableMsg")
        adp.Dispose()
        command.Dispose()
        con.Close()
        Return ds
    Catch ex As SqlException
     ...etc.                'As I read the trace output (below) we never got here nor to SQL

On this production webserver running IIS 6.0 Windows 2003, there are 3 virtual directories within the default web site (Zipeee,zVersion2,ZipeeeWebService).

Each virtual directory points to a separate physical dir on the c drive of the webserver. Both the production Zipeee and the newVersion zVersion2 make use of proxy class called ProxyZipeeeService.dll. I've taken great care in the publishing of the main project Zipeee and the webservices it needs. For example, on a developement server using Visual Studio2008, I've built and tested all 5 projects (webservice1, webservice2, primarywebapp (i.e.zipeee), proxyclassforWS1, proxyclassforWS2). The newest versions of all of these DLLs was tagged with an assembly version chosen to be 1.6. They all work on my dev machine and I published WS1,WS2 and zipeee to a staging server (IIS 6.0) and they all work there too. Then I publish to the public server hosting the URLs above. The new version of the web app goes into separate folders on the c drive and pointed to by vDir zVersion2. It should work but fails to render even the first page because of this WS error.

I traced the failure of zVersion2 (it calls webmethod GetMessageByType in page load event and fails right away). Here it is (not very long but formatting in SO here is a bit messy):

System.Web.Services.Asmx Information: 0 : Calling XmlSerializer [Create XmlSerializer] Method: System.Xml.Serialization.XmlSerializer#1669721556::FromMappings(System.Xml.Serialization.XmlMapping[]#40041277=[356], ProxyZipeeeService.WSZipeee.Zipeee#50200644=ProxyZipeeeService.WSZipeee.Zipeee) Caller: System.Web.Services.Protocols.SoapClientType#24827179::.ctor(ProxyZipeeeService.WSZipeee.Zipeee#50200644=ProxyZipeeeService.WSZipeee.Zipeee) ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:45.6541439Z Timestamp=47298006836 System.Web.Services.Asmx Information: 0 : Return from XmlSerializer [Create XmlSerializer] Caller: System.Web.Services.Protocols.SoapClientType#24827179::.ctor(ProxyZipeeeService.WSZipeee.Zipeee#50200644=ProxyZipeeeService.WSZipeee.Zipeee) ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:45.7791255Z Timestamp=47298376293 System.Web.Services.Asmx Information: 0 : Calling XmlSerializer [Create XmlSerializer] Method: System.Xml.Serialization.XmlSerializer#1669721556::FromMappings(System.Xml.Serialization.XmlMapping[]#64844482=[160], ProxyEmergencyService.WSEmergency.Emergency#88831384=ProxyEmergencyService.WSEmergency.Emergency) Caller: System.Web.Services.Protocols.SoapClientType#46729429::.ctor(ProxyEmergencyService.WSEmergency.Emergency#88831384=ProxyEmergencyService.WSEmergency.Emergency) ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:45.8572390Z Timestamp=47298680452 System.Web.Services.Asmx Information: 0 : Return from XmlSerializer [Create XmlSerializer] Caller: System.Web.Services.Protocols.SoapClientType#46729429::.ctor(ProxyEmergencyService.WSEmergency.Emergency#88831384=ProxyEmergencyService.WSEmergency.Emergency) ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:45.9353525Z Timestamp=47298924420 System.Web.Services.Asmx Information: 0 : Calling XmlSerializer [Write Request] Method: Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer192#13256970::Serialize(System.Xml.XmlTextWriter#52203868=.., System.Object[]#72766=[1], (null), (null)) Caller: ProxyZipeeeService.WSZipeee.Zipeee#654897::Serialize() ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:46.0915795Z Timestamp=47299598906 System.Web.Services.Asmx Information: 0 : Return from XmlSerializer [Write Request] Caller: ProxyZipeeeService.WSZipeee.Zipeee#654897::Serialize() ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:46.0915795Z Timestamp=47299606361 System.Web.Services.Asmx Information: 0 : Calling WebRequest.GetResponse Method: System.Net.HttpWebRequest#5894079::GetResponse() Caller: ProxyZipeeeService.WSZipeee.Zipeee#654897::GetWebResponse() ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:46.0915795Z Timestamp=47299607492 System.Web.Services.Asmx Error: 0 : Exception caught in ProxyZipeeeService.WSZipeee.Zipeee#654897::GetWebResponse. System.Net.WebException: The remote server returned an error: (400) Bad Request. ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:46.0915795Z Timestamp=47299629487 System.Web.Services.Asmx Error: 0 : Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse() at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:46.0915795Z Timestamp=47299654807 System.Web.Services.Asmx Information: 0 : Calling XmlSerializer [Write Request] Method: Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer192#13256970::Serialize(System.Xml.XmlTextWriter#53046711=.., System.Object[]#7658356=[1], (null), (null)) Caller: ProxyZipeeeService.WSZipeee.Zipeee#1816341::Serialize() ProcessId=1456 LogicalOperationStack= ThreadId=1 DateTime=2010-08-06T01:58:56.9024879Z Timestamp=47338202360

A: 

Try to do the following: 1. Add a new Service Reference named wsZipeee pointing to the Web Service 2. From the Calling location (another Web App, Winform, et al):

Dim ws as New wsZipeee.ZipeeeSoapClient()
Dim dsStandardMsg As DataSet 
dsStandardMsg = ws.GetMessageByType(BizConstants.MsgType.Standard)

By creating a new Service Reference, this will handle the proxy and allow you to cleanly call it. I am assuming the name of the service reference, web service, and method you want to call

websch01ar
Thanks very much for the suggestion. Service Reference and ZipeeeSoapClient suggests to me WCF. I am using ASMX and cannot convert at this point. WS1 is my shorthand for ZipeeeWebService and the call to that is the one that seems to be failing. WS2 is simply shorthand for another webservice (not a problem here). Perhaps I've misunderstood your idea ??
John Galt
A: 

As noted above, the main site used Proxy DLLs to communicate to the web service(s). In Visual Studio each Proxy project had a Web Reference (.wsdl file, etc.) and a generated app.config file. In one of these 2 proxy projects, the app.config file retained the original settings (which of course worked on my desktop dev machine and my staging web server):

<applicationSettings>
    <ProxyZipeeeService.My.MySettings>
        <setting name="ProxyZipeeeService_WSZipeee_Zipeee" serializeAs="String">
            <value>http://localhost/ZipeeeWebService/Zipeee.asmx&lt;/value&gt;
        </setting>
    </ProxyZipeeeService.My.MySettings>
</applicationSettings>

Note the localhost value above.

It turns out that when deployed to the production server, there is a host header value for the default web site and another web site on the same IIS machine. Later I discovered more about the fallout from this setup and came to realize that when the main site tried to access the web service via localhost it failed because localhost is not found amoung the 2 host header values. Therefore going back to Vstudio and changing the web reference as follows fixed the problem:

<applicationSettings>
    <ProxyZipeeeService.My.MySettings>
        <setting name="ProxyZipeeeService_WSZipeee_Zipeee" serializeAs="String">
            <value>http://www.zipeee.com/ZipeeeWebService/Zipeee.asmx&lt;/value&gt;
        </setting>
    </ProxyZipeeeService.My.MySettings>
</applicationSettings>
John Galt