我想写一个Soap的客户端,用来调用PHP写成的Web Service。通过VS添加Web引用或者服务引用,都会出问题,可以成功发现服务,也引用进来了,但是却没有任何类生成,只是生成了命名空间。但是这个Service使用PHP自己的SoapClient却可以成功使用,估计是这个WebService写的不是很规范。我看过.net的SOAP的XML,要有很多规范定义,而PHP写的却少了很多。版本是SOAP1.1的。所以,如果VS解决不了问题的话,我可能要手动写代码来引用Service,然后在运行时动态调用,而不是依靠VS。估计是用了System.Web.Service.Protocols下的命名空间,但是具体怎么用,不大会,对与Web Service 我还只能了解一些SOAP、XML和WSDL,对于UDDI、disco等还不是很清楚。
附上PHP的SOAP生成的WSDL<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
    name="Magento" targetNamespace="urn:Magento">
    <types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
            <complexType name="FixedArray">
                <complexContent>
                    <restriction base="soapenc:Array">
                        <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:anyType[]" />
                    </restriction>                </complexContent>
            </complexType>
        </schema>
    </types>
    <message name="call">
        <part name="sessionId" type="xsd:string" />
        <part name="resourcePath" type="xsd:string" />
        <part name="args" type="xsd:anyType" />
    </message>    <message name="callResponse">
        <part name="callReturn" type="xsd:anyType" />
    </message>
    <message name="multiCall">
        <part name="sessionId" type="xsd:string" />
        <part name="calls" type="typens:FixedArray" />
        <part name="options" type="xsd:anyType" />
    </message>
    <message name="multiCallResponse">        <part name="multiCallReturn" type="typens:FixedArray" />
    </message>
    <message name="endSession">
        <part name="sessionId" type="xsd:string" />
    </message>
    <message name="endSessionResponse">
        <part name="endSessionReturn" type="xsd:boolean" />
    </message>
    <message name="login">        <part name="username" type="xsd:string" />
        <part name="apiKey" type="xsd:string" />
    </message>
    <message name="loginResponse">
        <part name="loginReturn" type="xsd:string" />
    </message>
    <message name="resources">
        <part name="sessionId" type="xsd:string" />
    </message>    <message name="resourcesResponse">
        <part name="resourcesReturn" type="typens:FixedArray" />
    </message>
    <message name="globalFaults">
        <part name="sessionId" type="xsd:string" />
    </message>
    <message name="globalFaultsResponse">
        <part name="globalFaultsReturn" type="typens:FixedArray" />
    </message>    <message name="resourceFaults">
        <part name="resourceName" type="xsd:string" />
        <part name="sessionId" type="xsd:string" />
    </message>
    <message name="resourceFaultsResponse">
        <part name="resourceFaultsReturn" type="typens:FixedArray" />
    </message>
    <message name="startSession" />
    <message name="startSessionResponse">        <part name="startSessionReturn" type="xsd:string" />
    </message>
    <portType name="Mage_Api_Model_Server_HandlerPortType">
        <operation name="call">
            <documentation>Call api functionality</documentation>
            <input message="typens:call" />
            <output message="typens:callResponse" />
        </operation>        <operation name="multiCall">
            <documentation>Multiple calls of resource functionality</documentation>
            <input message="typens:multiCall" />
            <output message="typens:multiCallResponse" />
        </operation>
        <operation name="endSession">
            <documentation>End web service session</documentation>
            <input message="typens:endSession" />            <output message="typens:endSessionResponse" />
        </operation>
        <operation name="login">
            <documentation>Login user and retrive session id</documentation>
            <input message="typens:login" />
            <output message="typens:loginResponse" />
        </operation>
        <operation name="startSession">            <documentation>Start web service session</documentation>
            <input message="typens:startSession" />
            <output message="typens:startSessionResponse" />
        </operation>
        <operation name="resources">
            <documentation>List of available resources</documentation>
            <input message="typens:resources" />
            <output message="typens:resourcesResponse" />        </operation>
        <operation name="globalFaults">
            <documentation>List of resource faults</documentation>
            <input message="typens:globalFaults" />
            <output message="typens:globalFaultsResponse" />
        </operation>
        <operation name="resourceFaults">
            <documentation>List of global faults</documentation>            <input message="typens:resourceFaults" />
            <output message="typens:resourceFaultsResponse" />
        </operation>
    </portType>
    <binding name="Mage_Api_Model_Server_HandlerBinding" type="typens:Mage_Api_Model_Server_HandlerPortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="call">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="multiCall">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="endSession">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="login">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="startSession">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="resources">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="globalFaults">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
        <operation name="resourceFaults">
            <soap:operation soapAction="urn:Mage_Api_Model_Server_HandlerAction" />
            <input>                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </input>
            <output>
                <soap:body namespace="urn:Magento" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </output>
        </operation>
    </binding>
    <service name="MagentoService">
        <port name="Mage_Api_Model_Server_HandlerPort" binding="typens:Mage_Api_Model_Server_HandlerBinding">            <soap:address location="http://192.168.3.101/magentotest/index.php/api/soap/index/" />
        </port>
    </service>
</definitions>

解决方案 »

  1.   

    自己曾经尝试继承SoapHttpClientProtocol,但没有思路。
      

  2.   

    是微软老是加扩展, 不是 php 不遵照 soapsoap 请求本身就是个 http 请求自己构造就行了
      

  3.   


    那么是不是自己写一个Http连接类然后自己解析XML呢?而调用的话就是自己构造XML请求?
      

  4.   

    比方说 csdn 回帖的:    const string REPLYTMPL = @"<?xml version=""1.0"" encoding=""utf-8""?>
    <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
      <soap:Body>
        <Reply xmlns=""http://www.csdn.net/"">
          <identity>
            <username>{0}</username>
            <password>{1}</password>
          </identity>
          <reply>
            <forumId>{2}</forumId>
            <topicUrl>{3}</topicUrl>
            <body>{4}</body>
            <editor>{5}</editor>
          </reply>
        </Reply>
      </soap:Body>
    </soap:Envelope>";
      

  5.   

    连接到 csdn 网站, 
    构造上面的 soap body, 再加个 http header    const string HEADER = @"POST {0} HTTP/1.1
    Host: {1}
    Content-Type: text/xml; charset=utf-8
    Content-Length: {2}
    SOAPAction: ""{3}""
    Connection: Close";最后合并为一个字节数组发过去就 ok 了.
      

  6.   

    呃动态调用不一样是要生成VS类么,VS那个只是帮助你事先生成以下而已。
    难道你要直接发送soap协议包?
      

  7.   


    问题是VS并没给我生成类,我可不想自己写SOAP包那么麻烦
      

  8.   

    不能吧web service 放到服务引用到 工程里面啊?