【问题标题】:Adding a PHP web reference in a .NET application在 .NET 应用程序中添加 PHP Web 引用
【发布时间】:2012-01-03 18:34:01
【问题描述】:

我正在尝试从我的 .Net Web 应用程序中添加和调用 PHP Web 服务。 我尝试在this 教程中添加参考,但收到此错误。

The HTML document does not contain Web service discovery information.

我看到了调用的方法。我运行了 svcutil,它返回了一些元数据和同样的错误。我也尝试了 wsdl.exe 并得到了同样的错误。我无法理解前进的最佳方式是什么。 我已经阅读了很多 SO 帖子和文章,但现在感觉有点困惑。 任何帮助都会非常感谢

编辑: 这是页面生成的xml。

<?xml version="1.0" encoding="utf-8"?>

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"

    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema"

    xmlns:tns="http://leopard-ext.its-dispatch.com/ws/request.php" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://leopard-ext.its-dispatch.com/ws/request.php">

    <types>

        <s:schema elementFormDefault="qualified" targetNamespace="http://leopard-ext.its-dispatch.com/ws/request.php">

            <s:element name="fetchImport">

                <s:complexType>

                    <s:sequence>

                        <s:element minOccurs="1" maxOccurs="1" name="accessKey" type="s:string" />

                        <s:element minOccurs="1" maxOccurs="1" name="requestURL" type="s:string" />

                        <s:element minOccurs="1" maxOccurs="1" name="requestFunction" type="s:string" />

                        <s:element minOccurs="1" maxOccurs="1" name="requestType" type="s:string" />

                        <s:element minOccurs="1" maxOccurs="1" name="ID" type="s:string" />

                    </s:sequence>

                </s:complexType>

            </s:element>

            <s:element name="fetchImportResponse">

                <s:complexType>

                    <s:sequence>

                        <s:element minOccurs="1" maxOccurs="1" name="fetchImport" type="s:string" />

                    </s:sequence>

                </s:complexType>

            </s:element>

            <s:element name="getLoads">

                <s:complexType>

                    <s:sequence>

                        <s:element minOccurs="0" maxOccurs="1" name="accessKey" type="s:string" />

                    </s:sequence>

                </s:complexType>

            </s:element>

            <s:element name="getLoadsResponse">

                <s:complexType>

                    <s:sequence>

                        <s:element minOccurs="1" maxOccurs="1" name="getLoads" type="s:string" />

                    </s:sequence>

                </s:complexType>

            </s:element>

        </s:schema>

    </types>

    <message name="fetchImportSoapIn">

        <part name="parameters" element="tns:fetchImport" />

    </message>

    <message name="fetchImportSoapOut">

        <part name="parameters" element="tns:fetchImportResponse" />

    </message>

    <message name="getLoadsSoapIn">

        <part name="parameters" element="tns:getLoads" />

    </message>

    <message name="getLoadsSoapOut">

        <part name="parameters" element="tns:getLoadsResponse" />

    </message>

    <portType name="ITSDispatchServiceSoap">

        <operation name="fetchImport">

            <input message="tns:fetchImportSoapIn" />

            <output message="tns:fetchImportSoapOut" />

        </operation>

        <operation name="getLoads">

            <input message="tns:getLoadsSoapIn" />

            <output message="tns:getLoadsSoapOut" />

        </operation>

    </portType>

    <binding name="ITSDispatchServiceSoap" type="tns:ITSDispatchServiceSoap">

        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

        <operation name="fetchImport">

            <soap:operation soapAction="http://leopard-ext.its-dispatch.com/ws/request.php/fetchImport" style="document" />

            <input>

                <soap:body use="literal" />

            </input>

            <output>

                <soap:body use="literal" />

            </output>

        </operation>

        <operation name="getLoads">

            <soap:operation soapAction="http://leopard-ext.its-dispatch.com/ws/request.php/getLoads" style="document" />

            <input>

                <soap:body use="literal" />

            </input>

            <output>

                <soap:body use="literal" />

            </output>

        </operation>

    </binding>

    <service name="ITSDispatchService">

        <port name="ITSDispatchServiceSoap" binding="tns:ITSDispatchServiceSoap">

            <soap:address location="http://leopard-ext.its-dispatch.com/ws/request.php" />

        </port>

    </service>

</definitions>

【问题讨论】:

  • 有问题的 Web 服务是否为您公开了 WSDL?
  • @plenderj 不像 wcf 服务那样。看起来它只是一个带有 4 个文本框的 php 页面。它应该公开一个 wsdl
  • @plenderj 我试图下载 wsdl 保存它并从 vs cmd 提示符运行 wdsl.exe 并输出到一个 vb 文件它给了我一个错误。 XML 文档 中的错误不是预期的。
  • 您说您尝试下载 wsdl - 您实际上有指向 WSDL 的链接吗?如果您在网络浏览器中查看它,您应该会看到 XML 等?
  • @plenderj 我必须查看源代码才能看到 xml。

标签: php .net vb.net web-services


【解决方案1】:

查看您发布的 wsdl,在“its-dispatch.com”网站上,它们的标题设置错误(他们说它们是 text/html 而不是 text/xml)。

您有几个选择,最简单的方法是将上面粘贴的文本作为文本文件保存到磁盘的某个位置。然后使用 Web 引用导入器将其导入(您可以通过转到“添加服务引用”,单击“高级”并选择“添加 Web 引用”并使用 file:// 协议指向您的文本文件来找到它。

例如,我尝试使用:"file:///C:/Users/Kris/Desktop/test.wsdl" 并获得了有效的网络参考。然后转到项目中的 Web 参考并将“Web 参考 URL”从“file:///C:/Users/Kris/Desktop/test.wsdl”更改为“http://leopard-ext.its-dispatch.com/ws/request.php?wsdl”,一切都应该适合你。

我使用了 Visual Studio 为 Web 服务提供的默认名称,建议更改它们以符合您的命名约定。

你可以在这里找到我创建的示例项目:http://wikisend.com/download/299780/WindowsFormsApplication1.zip

【讨论】:

  • 它响应的 html 文档不包含 Web 服务发现信息。
  • 不,它响应了一个 XML 文档(您看到的四个框),该文档具有由 Web 服务器指定的错误内容类型(实际上它是 PHP 返回的默认类型)。您已经拥有 WSDL(您已将其粘贴到您的问题中),将其保存到文件中并加载它,如我的回答中所示。如果您确实遇到问题,请参阅我创建的项目,我将其链接在答案的底部。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多