2010-08-06 122 views
0

我得到一個故障在我的web應用程序中調用一個Web服務:web服務的調用失敗,HTTP狀態400錯誤的請求

服務器錯誤/ zVersion2a「應用程序。 請求失敗,HTTP狀態400:錯誤請求。

下面是對Web服務本身的鏈接(這工作):

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

這裏是到[製作] Web應用程序的鏈接,呼籲第一頁面加載WS:

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

下面是失敗調用此相同的WS [NEWVERSION] Web應用程序的鏈接:

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

這裏是在調用頁面的源代碼:

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 

這裏是Reference.vb在代理代碼:

<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 

最後,這裏是代碼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 

在運行IIS 6.0 Windows 2003的此生產Web服務器上,默認網站(Zipeee,zVersion2,ZipeeeWebService)中有3個虛擬目錄。

每個虛擬目錄指向Web服務器的C驅動器上的一個單獨的物理目錄。生產Zipeee和newVersion zVersion2都使用代理類ProxyZipeeeService.dll。我在發佈主要項目Zipeee和它所需的Web服務時非常謹慎。例如,在使用Visual Studio2008的開發服務器上,我已經構建和測試了所有5個項目(webservice1,webservice2,primarywebapp(egzipeee),代理類對WS1,代理類對WS2)。所有這些DLL的最新版本都被標記爲彙編版本選擇爲1.6。他們都在我的開發機器上工作,並將WS1,WS2和zipeee發佈到登臺服務器(IIS 6.0),他們也都在那裏工作。然後我發佈到託管上述URL的公共服務器。新版本的Web應用程序進入c驅動器上的單獨文件夾,並由vDir zVersion2指向。它應該可以工作,但由於此WS錯誤,無法呈現第一頁。

我跟蹤了zVersion2的失敗(它在頁面加載事件中調用webmethod GetMessageByType並立即失敗)。這是(不是很長,但在格式化所以這裏是一個有點亂):

System.Web.Services.Asmx信息:0:調用XmlSerializer的[創建XmlSerializer的] 方法:的System.Xml.Serialization。 (System.Xml.Serialization.XmlMapping []#40041277 = [356],ProxyZipeeeService.WSZipeee.Zipeee#50200644 = ProxyZipeeeService.WSZipeee.Zipeee) 調用方:System.Web.Services.Protocols.SoapClientType# 24827179 ::。構造函數(ProxyZipeeeService.WSZipeee.Zipeee#50200644 = ProxyZipeeeService.WSZipeee。Zipeee) 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58:45.6541439Z 時間戳= 47298006836 System.Web.Services.Asmx信息:0:從XmlSerializer的返回[創建的XmlSerializer] 呼叫者:System.Web.Services.Protocols.SoapClientType#24827179 ::構造函數(ProxyZipeeeService.WSZipeee.Zipeee#50200644 = ProxyZipeeeService.WSZipeee.Zipeee) 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08- 06T01:58:45.7791255Z Timestamp = 47298376293 System.Web.Services.Asmx信息:0:調用XmlSerializer [創建XmlSerializer] 方法:System.Xml.Serialization.XmlSerializer#1669721556 :: FromMappings(System.Xml.Serialization.XmlMapping []#64844482 = [160],ProxyEmergencyService.WSEmergency.Emergency#88831384 = ProxyEmergencyService.WSEmergency.Emergency) 調用方:System .Web.Services.Protocols.SoapClientType#46729429 ::構造函數(ProxyEmergencyService.WSEmergency.Emergency#88831384 = ProxyEmergencyService.WSEmergency.Emergency) 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58 :45.8572390Z Timestamp = 47298680452 System.Web.Services.Asmx信息:0:從XmlSerializer返回[Create XmlSerializer] 調用方:System.Web.Services.Protocols.SoapClientType#46729429 ::。ctor(ProxyEmergencyService.WSEmergency.Emergency #88831384 = ProxyEmerge ncyService.WSEmergency.Emergency) 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58:45.9353525Z 時間戳= 47298924420 System.Web.Services.Asmx信息:0:調用XmlSerializer的[寫請求] 方法:Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer192#13256970 ::序列化(System.Xml.XmlTextWriter#52203868 = ..,System.Object的[]#72766 = [1],(空),(空) ) 來電:ProxyZipeeeService.WSZipeee.Zipeee#654897 ::序列化() 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58:46.0​​915795Z 時間戳= 4729959 8906 System.Web.Services.Asmx信息:0:從XmlSerializer的返回[寫請求] 主叫:ProxyZipeeeService.WSZipeee.Zipeee#654897 ::序列化() 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010 -08-06T01:58:46.0​​915795Z 時間戳= 47299606361 System.Web.Services.Asmx信息:0:調用WebRequest.GetResponse 方法:System.Net.HttpWebRequest#5894079 ::的GetResponse() 來電:ProxyZipeeeService.WSZipeee .Zipeee#654897 :: GetWebResponse() ProcessId = 1456 LogicalOperationStack = ThreadId = 1 DateTime = 2010-08-06T01:58:46.0​​91 5795Z 時間戳= 47299607492 System.Web.Services.Asmx錯誤:0:在ProxyZipeeeService.WSZipeee.Zipeee中捕獲的異常#654897 :: GetWebResponse。 System.Net.WebException:遠程服務器返回錯誤:(400)錯誤的請求。 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58:46.0​​915795Z 時間戳= 47299629487 System.Web.Services.Asmx錯誤:0:異常詳細信息: System.Net.WebException:遠程服務器返回錯誤:(400)錯誤的請求。 在System.Net.HttpWebRequest.GetResponse() 在System.Web.Services.Protocols。WebClientProtocol.GetWebResponse(WebRequest的請求) 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58:46.0​​915795Z 時間戳= 47299654807 System.Web.Services.Asmx信息:0:調用XmlSerializer的[寫請求] 方法:Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer192#13256970 :: Serialize(System.Xml.XmlTextWriter#53046711 = ..,System.Object []#7658356 = [1],(null),(null )) 來電:ProxyZipeeeService.WSZipeee.Zipeee#1816341 ::序列化() 的ProcessID = 1456 LogicalOperationStack = 的ThreadId = 1 日期時間= 2010-08-06T01:58:56.9024879Z 時間戳= 47338202360

回答

0

儘量做到以下幾點:1。 添加新的服務參考命名wsZipeee指向Web服務 2.從主叫位置(另一個Web應用程序,WinForm的,等):

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

通過創建一個新的服務引用,這將處理代理並允許您乾淨地調用它。我假設您想要調用的服務引用,Web服務和方法的名稱

+0

非常感謝您的建議。 Service Reference和ZipeeeSoapClient向我建議WCF。我正在使用ASMX,現在無法轉換。 WS1是ZipeeeWebService的縮寫,對此的調用似乎是失敗的。 WS2只是另一個web服務的簡寫(這裏沒有問題)。也許我誤解了你的想法? – 2010-08-07 02:24:19

0

如上所述,主站點使用代理DLL與Web服務進行通信。在Visual Studio中,每個代理項目都有一個Web引用(.wsdl文件等)和一個生成的app.config文件。在這2個代理項目之一,app.config文件保留了原來的設置(這當然是我的桌面開發機器上工作,我的分期Web服務器):

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

注意上面的本地主機值。

事實證明,當部署到生產服務器時,默認網站和同一IIS機器上的另一個網站有一個主機標頭值。後來,我從這個設置中發現了更多關於此後果的信息,並意識到當主站點試圖通過本地主機訪問Web服務時,它會失敗,因爲在2個主機標頭值中找不到localhost。因此,回到Vstudio並更改Web參考如下解決了問題:

<applicationSettings> 
    <ProxyZipeeeService.My.MySettings> 
     <setting name="ProxyZipeeeService_WSZipeee_Zipeee" serializeAs="String"> 
      <value>http://www.zipeee.com/ZipeeeWebService/Zipeee.asmx</value> 
     </setting> 
    </ProxyZipeeeService.My.MySettings> 
</applicationSettings> 
相關問題