Skip to main content
 首页 » 编程设计

c#之无法导入 WSDL 服务 "targetNamespace ' urn :webservice' not found'

2024年01月01日26zengkefu

过去几个小时,我一直在努力将 WSDL 网络服务导入 Visual Studio 2010。慢慢地,我一直在努力解决我的 WSDL,解决其他问题,直到遇到这个问题:

Warning 1   Custom tool warning: Cannot import wsdl:portType 
Detail: An exception was thrown while running a WSDL import extension:  
System.ServiceModel.Description.XmlSerializerMessageContractImporter 
Error: Schema with target namespace 'urn:WebService' could not be found. 
XPath to Error Source: 
//wsdl:definitions[@targetNamespace='urn:WebService']/wsdl:portType[@name='DataPort']    
C:\* blablabla *\WeGotchaService\Reference.svcmap   1   1   Gotcha! 

我已经尝试了 Google 可以为我提供的每一件小事,包括:

  1. 禁用“在引用的程序集中重用类型”
  2. 将集合类型设置为 system.collections.generic.list
  3. 来回更改大部分属性。
  4. 从别人那里复制一个 WSDL 文件,只是为了看看它是否能工作(它没有)

这是我的 .wsdl 文件:

<?xml version="1.0"?> 
<definitions  
  name="WebService" 
  targetNamespace="urn:WebService"  
  xmlns:tns="urn:WebService"   
  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/"> 
 
  <types> 
     <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="GetData"> 
      <xsd:element name="getCustomerID" type="xsd:int" /> 
      <xsd:element name="DataResponse" type="xsd:string" /> 
     </xsd:schema> 
  </types> 
 
  <message name="doGetCustomerID"> 
    <part name="ID" type="tns:getCustomerID" /> 
  </message> 
 
  <message name="doDataResponse"> 
    <part name="return" type="tns:DataResponse" /> 
  </message> 
 
  <portType name="DataPort"> 
    <operation name="getData"> 
      <input message="tns:doGetCustomerID" /> 
      <output message="tns:doDataResponse" /> 
    </operation> 
  </portType> 
 
  <binding name="DataBinding" type="tns:DataPort"> 
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> 
    <operation name="getData"> 
      <soap:operation soapAction="urn:getDataAction" /> 
      <input> 
        <soap:body use="encoded" namespace="urn:GetData"     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </input> 
      <output> 
        <soap:body use="encoded" namespace="urn:GetData" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </output> 
    </operation> 
  </binding> 
 
  <service name="WeGotchaService"> 
     <port name="DataPort" binding="tns:DataBinding"> 
       <soap:address location="http://localhost/weGotcha/servicehandler.php" /> 
     </port> 
  </service> 
 
</definitions> 

服务处理器.php

<?php 
if(!extension_loaded("soap")) 
{ 
  dl("php_soap.dll"); 
} 
 
ini_set("soap.wsdl_cache_enabled", "0"); 
$server = new SoapServer("getPersonen.wsdl"); 
 
function getData($persoon_id) 
{ 
    mysql_connect("localhost", "root", ""); 
    mysql_select_db('gotcha_dbtemplate'); 
    $sql = "SELECT * FROM lessen"; 
$sql = mysql_query($sql); 
while($row = mysql_fetch_array($sql)) 
{ 
  $result[] = $row; 
} 
mysql_close(); 
 
  return $result; 
} 
 
$server->addFunction("getData"); 
$server->handle(); 
?>                                                       

我不知道如何解决这个问题。还有一些其他错误,但这些是由于它在导入 portType 时遇到问题(绑定(bind)导入错误,因为 portType 不正确,端口错误,因为依赖于绑定(bind))

我希望有人知道问题出在哪里,我不知道:( 谢谢。

更新:我的 test.php 工作正常,它确实从 getData 方法输出结果。

请您参考如下方法:

我已经改变了很多我记不清了,现在它可以工作了:

<?xml version="1.0"?> 
<definitions xmlns:tns="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl"     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="WebService" targetNamespace="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl"> 
<types> 
    <xs:schema elementFormDefault="qualified" targetNamespace="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl"> 
        <xsd:element name="getCustomerID" type="xsd:int"/> 
        <xs:complexType name="Persoon"> 
            <xs:sequence> 
                <xs:element name="ID" type="xsd:int"/> 
                <xs:element name="Voornaam" type="xsd:string"/> 
                <xs:element name="Achternaam" type="xsd:string"/> 
                <xs:element name="Adres" type="xsd:string"/> 
                <xs:element name="Postcode" type="xsd:string"/> 
                <xs:element name="Woonplaats" type="xsd:string"/> 
                <xs:element name="Email_adres" type="xsd:string"/> 
                <xs:element name="Telefoonnummer" type="xsd:string"/> 
                <xs:element name="CBR_Kandidaatnummer" type="xsd:string"/> 
                <xs:element name="Rijbewijs" type="xsd:int"/> 
                <xs:element name="Laatste_keer_bewerkt" type="xsd:dateTime"/> 
            </xs:sequence> 
        </xs:complexType> 
        <xs:complexType name="PersoonList"> 
            <xs:complexContent> 
                <xs:restriction base="soapenc:Array"> 
                    <xs:sequence> 
                        <xs:element name="Persoon" type="tns:Persoon" maxOccurs="unbounded"/> 
                    </xs:sequence> 
                </xs:restriction> 
            </xs:complexContent> 
        </xs:complexType> 
    </xs:schema> 
</types> 
<message name="doGetCustomerID"> 
    <part name="CustomerID" type="xsd:int"/> 
</message> 
<message name="doGetPersoonDataResponse"> 
    <part name="return" type="tns:PersoonList"/> 
</message> 
<portType name="DataPort"> 
    <operation name="getPersoonData"> 
        <input message="tns:doGetCustomerID"/> 
        <output message="tns:doGetPersoonDataResponse"/> 
    </operation> 
</portType> 
<binding name="DataBinding" type="tns:DataPort"> 
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <operation name="getPersoonData"> 
        <soap:operation soapAction="urn:getDataAction"/> 
        <input> 
            <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:GetData"/> 
        </input> 
        <output> 
            <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:GetData"/> 
        </output> 
    </operation> 
</binding> 
<service name="WeGotchaService"> 
    <port name="DataPort" binding="tns:DataBinding"> 
        <soap:address location="http://localhost/weGotcha/servicehandler/servicehandler.php"/> 
    </port> 
</service>