我有一个已知的工作Web服务,它配置为SOAP和REST绑定。我可以使用测试工具调用它,我可以看到SOAP POST,然后SOAP响应都很好。
然而,当我尝试在Visual Studio 2010 Cassini中托管服务时,我会遇到以下行为:
1)当调用端点作为REST并使用WebChannelFactory类时,服务正常工作
2)当将端点作为SOAP调用并使用ChannelFactory类时,服务会抛出错误并得到400响应。 (错误如下)。
3)当将端点作为SOAP调用并使用c#SOAP引用时,服务正常工作。
难以理解?
我想知道是否与我使用Cassini版本的端口号这一事实有关?
就在人们开始告诉我在IIS中托管之前我真的需要在Cassini中使用它作为WCF教程的一部分
这是原始HTTP请求不起作用(当针对正在运行的IIS部署和错误的Visual Studio Web服务器调用时。
IIS工作:
POST http://api.dev.videolibraryserver.com/VLSContentService.svc/soap/ HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/IVLSContentService/EchoWithGet"
Host: api.dev.videolibraryserver.com
Content-Length: 180
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><EchoWithGet xmlns="http://tempuri.org/"><message>Hello World!</message></EchoWithGet></s:Body></s:Envelope>
VISUAL STUDIO(CASSINI) - 不工作:
POST http://127.0.0.1:52587/VLSContentService.svc//soap HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/IVLSContentService/EchoWithGet"
Host: 127.0.0.1:52587
Content-Length: 180
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><EchoWithGet xmlns="http://tempuri.org/"><message>Hello World!</message></EchoWithGet></s:Body></s:Envelope>
使用CASSINI时的错误响应
HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 23 Jun 2011 10:42:09 GMT
Content-Length: 1209
Content-type: text/html;charset=utf-8
Connection: Close
<html>
<head>
<title>Bad Request</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: 8pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><h1>Server Error in '/' Application.<hr width=100% size=1 color=silver></h1>
<h2> <i>HTTP Error 400 - Bad Request.</i> </h2></span>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> ASP.NET Development Server 10.0.0.0
</font>
</body>
</html>
.NET EXCEPTION(虽然无关,因为服务器没有返回响应)
C:\Users\Peter Heard\Desktop\TestClient\Debug>TestClient.exe "http://ipv4.fiddle
r:52587/VLSContentService.svc/" "Hello World!" 2
***************************
About to call SOAP web service interface TestSOAPUsingChannelFactory()
There was an errorSystem.ServiceModel.ProtocolException: The remote server retur
ned an unexpected response: (400) Bad Request. ---> System.Net.WebException: The
remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResp
onse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factor
y, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeS
pan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message messag
e, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at IVLSContentService.EchoWithGet(String message)
at TestClient.Program.TestSOAPUsingChannelFactory() in C:\Repositories\VideoL
ibraryServer\trunk\prototypes\Hml_Api_Wcf\TestClient\Program.cs:line 96
at TestClient.Program.Main(String[] args) in C:\Repositories\VideoLibraryServ
er\trunk\prototypes\Hml_Api_Wcf\TestClient\Program.cs:line 47
的 的 ** * ** * * 更新< / EM> * ** * ** * ** * ***
虽然这个问题的答案是正确的。我的测试不是。我实际上试图在IIS和Cassini的url中传递'//',但它对Cassini没有用。显然,IIS在处理引号时更加健壮。下面的评论谈到这个,但我想我会更新答案。
答案 0 :(得分:1)
“不工作”请求的第一行在网址中有一个额外的斜杠:
POST http://127.0.0.1:52587/VLSContentService.svc//soap HTTP/1.1
^