2010-08-06 119 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>