【问题标题】:The request failed with HTTP status 404: Not Found请求失败,HTTP 状态为 404:未找到
【发布时间】:2012-11-26 10:10:48
【问题描述】:

我正在尝试从 .Net 客户端调用 php soap web 服务,但出现以下错误:

System.Net.WebException was unhandled by user code
  Message="**The request failed with HTTP status 404: Not Found**."
  Source="System.Web.Services"
  StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at php_webservice_test_CS.WebReference.MyService.testServer() in c:\documents and settings\gdeshpande.parcdev.003\my documents\visual studio 2008\projects\php_webservice_test_cs\php_webservice_test_cs\web references\webreference\reference.cs:line 79
       at php_webservice_test_CS._Default.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\gdeshpande.PARCDEV.003\My Documents\Visual Studio 2008\Projects\php_webservice_test_CS\php_webservice_test_CS\Default.aspx.cs:line 23
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

我无法得到问题是 php Soap 服务器端或 .Net 客户端。我是 php 新手。

请帮助任何人。

以下是 SOAP 服务器代码:

ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("http://10.20.1.161/api/soap/report.wsdl");
$server->addFunction("testServer");
$server->handle();

以下是 SOAP .Net 客户端代码:

 protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                MyService ms = new MyService(); 
                Object ac = ms.testServer();
            }
            catch (Exception ae)
            {
                Response.Write(ae);
            }
        }

我想分享我的 WSDL,就是这样......

<wsdl:definitions xmlns:tns="http://10.20.1.161/api/soap/"
 targetNamespace="http://10.20.1.161/api/soap/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
 <wsdl:types>
  <s:schema targetNamespace="http://10.20.1.161/api/soap/">

   <s:complexType name="stringArray">
    <s:annotation>
     <s:documentation> A string array type </s:documentation>
    </s:annotation>
    <s:complexContent>

     <s:restriction base="soapenc:Array">
      <s:attribute ref="soapenc:arrayType" wsdl:arrayType="s:string[]"/>
     </s:restriction>
    </s:complexContent>
   </s:complexType>   
  </s:schema>
 </wsdl:types> 

 <wsdl:message name="reportRequest" />

 <wsdl:message name="reportResponse">
  <wsdl:part name="resParam" type="tns:stringArray"/>

 </wsdl:message> 

 <wsdl:portType name="MyPortType">
   <wsdl:operation name="testServer">
   <wsdl:documentation> Get a complex type object </wsdl:documentation>
    <wsdl:input message="tns:reportRequest"/>
    <wsdl:output message="tns:reportResponse"/>
  </wsdl:operation>
 </wsdl:portType>


 <wsdl:binding name="MyPortType" type="tns:MyPortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

  <wsdl:operation name="testServer">
   <soap:operation soapAction="http://10.20.1.161/api/soap/testServer"/>
   <wsdl:input>
    <soap:body use="encoded" namespace="http://10.20.1.161/api/soap/"
     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </wsdl:input>
   <wsdl:output>
    <soap:body use="encoded" namespace="http://10.20.1.161/api/soap/"
     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

   </wsdl:output>
  </wsdl:operation>
 </wsdl:binding>

 <wsdl:service name="MyService">
  <wsdl:port name="MyPortType" binding="tns:MyPortType">
   <soap:address location="http://10.20.1.161/api/soap/parc_web_servise.php"/>
  </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

请帮忙..

【问题讨论】:

  • 您真的可以在您的网络浏览器中查看10.20.1.161/api/soap/report.wsdl 吗?你的 php 服务器在运行吗?
  • 404 not found 很清楚,不是吗?您确定网址正确吗?
  • 在浏览器中自己下载 WSDL URL。底部是您的客户端将尝试使用的端点 URL。你能看到那个 URL - 它是否存在/在 SOAP 请求之外工作?
  • 你好 Mike de Klerk,thanx 回复,-是的 url 在 web 浏览器中工作正常,即使在将 refrence 添加到 .net 项目时也没有显示错误......当我做一个调用错误“显示http状态404”
  • 嗨 Rup,thanx 回复,我应该如何下载 wsdl url,如果它使用 10.20.1.161/api/soap/report.wsdl,那么这在浏览器中工作正常..

标签: c# php .net soap wsdl


【解决方案1】:

您收到 404 响应,404 或 Not Found 错误消息是 HTTP 标准响应代码,表示客户端能够与服务器通信,但服务器找不到请求的内容。

确保您的网址有效,尝试将您的链接放在浏览器中,看看是否正确,如果您请求的网址有特殊的标题 谷歌浏览器上有一个有用的扩展名为 PostMan 您可以根据需要添加标题并测试 url

【讨论】:

  • 嗨 Omar Freewan,感谢您的回复,浏览器中的链接很好,并且没有包含特殊标题...
【解决方案2】:

使用 IIS 附加所有权限。 控制面板 -> 打开和关闭 Windows 功能

【讨论】:

  • 然后重启你的机器。
猜你喜欢
  • 2014-05-22
  • 2013-04-10
  • 1970-01-01
  • 2022-11-13
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 2023-01-21
  • 2011-08-02
相关资源
最近更新 更多