gpt4 book ai didi

c# - 使用 Visual Studio Webserver 托管 WCF SOAP 端点时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-03 14:16:35 24 4
gpt4 key购买 nike

我有一个已知的工作网络服务,它被配置为 SOAP 和 REST 绑定(bind)。我可以使用测试工具来调用它,我可以看到 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 网络服务器调用时。

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>

使用卡西尼时的错误响应

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>&nbsp;ASP.NET Development Server 10.0.0.0

</font>

</body>
</html>

.NET 异常(虽然无关紧要,因为服务器没有返回响应)

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

*******更新*************

虽然这个问题的答案是正确的。我的测试没有。我实际上试图在 IIS 和 Cassini 的 URL 中传递一个“//”,但它对 Cassini 不起作用。显然 IIS 在处理引号时更加健壮。下面的评论谈到了这一点,但我想我会更新答案。

最佳答案

“不工作”请求的第一行在 URL 中有一个额外的斜线:

POST http://127.0.0.1:52587/VLSContentService.svc//soap HTTP/1.1
^

关于c# - 使用 Visual Studio Webserver 托管 WCF SOAP 端点时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6452861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com