服务引用未加载:找不到具有目标名称空间的模式

Bar*_*rdo 9 c# xsd soap wsdl web-services

我正在尝试为我的项目添加服务引用,并且我经常遇到同样的错误.

我用SOAP UI创建了一个似乎很好的模拟服务,然后我尝试向这个模拟服务添加服务引用,并出现错误:

Warning 14  Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:     System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'urn:oasis:names:tc:dss:1.0:core:schema' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/esign']/wsdl:portType[@name='EsignServiceSoap11PortType']    
Run Code Online (Sandbox Code Playgroud)

在wsdl上导入带有命名空间urn的架构:oasis:names:tc:dss:1.0:core:schema正在加载:

<wsdl:types>

      <schema xmlns="urn:oasis:names:tc:dss:1.0:core:schema">

           <import namespace="urn:oasis:names:tc:dss:1.0:core:schema" schemaLocation="oasis-dss-core-schema-v1.0-os.xsd"/>

      </schema>

    .....
</wsdl:types>
Run Code Online (Sandbox Code Playgroud)

我已经尝试将schemaLocation直接链接到与wsdl相同的文件夹中的文件,将其链接到私有服务器中发布的url,以及发布它的公共uri.

我总是得到同样的错误,我开始觉得可能我错了问题的根源.

任何见解都将非常感激.

更新:我注入了urn:oasis:names:tc:dss:1.0:core:我的wsdl文件中的schema完成定义,而不是尝试导入它.当我这样做时,SOAP UI仍然正确地创建了模拟服务,但是,当我尝试添加服务引用时,在服务发现期间抛出此错误:

The document was understood, but it could not be processed.
  - The WSDL document contains links that could not be resolved.
  - DTD is prohibited in this XML document.
Metadata contains a reference that cannot be resolved:    'http://elite8100-3:8088/mockEsignServiceSoap11Binding?WSDL'.
The content type text/html; charset=iso-8859-1 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 455 bytes of the response were: '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Body>
    <soap:Fault>
      <soap:Code>
    <soap:Value>Server</soap:Value>
  </soap:Code>
  <soap:Reason>
    <!--1 or more repetitions:-->
    <soap:Text xml:lang="en">Missing operation for soapAction [null] and body element [null] with SOAP Version [SOAP 1.2]</soap:Text>
  </soap:Reason>
</soap:Fault>
  </soap:Body>
</soap:Envelope>'.
The remote server returned an error: (500) Internal Server Error.
If the service is defined in the current solution, try building the solution and adding the service reference again.
Run Code Online (Sandbox Code Playgroud)

EDIT2:我在尝试创建代理时使用了Fiddler来检查http流量,如答案所示.在创建过程中,Fiddler在尝试访问mockService url时出现500内部服务器错误,来自服务器的响应是"SOAPAction缺失操作[null]和SOAP元素[SOAP 1.2]的body元素[null]".

目前,这是我用来创建mockService的WSDL.

 <wsdl:types>

      <schema xmlns="http://www.w3.org/2001/XMLSchema">

           <import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://aplicaciones.serpasa.es/CONTROLAMBIENTAL/oasis-dss-core-schema-v1.0-os.xsd"/>

      </schema>

      <schema xmlns="http://princast.es/esign/2.0/esign.xsd">

           <import namespace="http://princast.es/esign/2.0/esign.xsd" schemaLocation="http://aplicaciones.serpasa.es/CONTROLAMBIENTAL/esign.xsd"/>

      </schema>

 </wsdl:types>


 <wsdl:message name="SignRequestMessage">

      <wsdl:part element="dss:SignRequest" name="payload"/>

 </wsdl:message>

 <wsdl:message name="SignResponseMessage">

      <wsdl:part element="dss:SignResponse" name="payload"/>

 </wsdl:message>


 <wsdl:message name="VerifyRequestMessage">

      <wsdl:part element="dss:VerifyRequest" name="payload"/>

 </wsdl:message>

 <wsdl:message name="VerifyResponseMessage">

      <wsdl:part element="dss:VerifyResponse" name="payload"/>

 </wsdl:message>


 <wsdl:message name="GetSignInfoFromDocumentRequestMessage">

      <wsdl:part element="esign:SignInfoRequest" name="payload"/>

 </wsdl:message>

 <wsdl:message name="GetSignInfoFromDocumentResponseMessage">

      <wsdl:part element="esign:SignInfo" name="payload"/>

 </wsdl:message>


 <wsdl:message name="GetSignConfigurationRequestMessage">

      <wsdl:part element="esign:SignConfigurationRequest" name="payload"/>

 </wsdl:message>

 <wsdl:message name="GetSignConfigurationResponseMessage">

      <wsdl:part element="esign:SupportedSignConfiguration" name="payload"/>

 </wsdl:message>


<!-- Port -->


 <wsdl:portType name="EsignServiceSoap11PortType">


      <wsdl:operation name="sign">

           <wsdl:input message="impl:SignRequestMessage" name="signRequest"/>

           <wsdl:output message="impl:SignResponseMessage" name="signResponse"/>

      </wsdl:operation>


      <wsdl:operation name="verify">

           <wsdl:input message="impl:VerifyRequestMessage" name="verifyRequest"/>

           <wsdl:output message="impl:VerifyResponseMessage" name="verifyResponse"/>

      </wsdl:operation>


      <wsdl:operation name="getSignConfiguration">

           <wsdl:input message="impl:GetSignConfigurationRequestMessage" name="getSignConfigurationRequest"/>

           <wsdl:output message="impl:GetSignConfigurationResponseMessage" name="getSignConfigurationResponse"/>

      </wsdl:operation>


      <wsdl:operation name="getSignInfoFromDocument">

           <wsdl:input message="impl:GetSignInfoFromDocumentRequestMessage" name="getSignInfoFromDocumentRequest"/>

           <wsdl:output message="impl:GetSignInfoFromDocumentResponseMessage" name="getSignInfoFromDocumentResponse"/>

      </wsdl:operation>


 </wsdl:portType>


<!-- Binding -->

 <wsdl:binding name="EsignServiceSoap11Binding" type="impl:EsignServiceSoap11PortType">


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


      <wsdl:operation name="sign">

           <wsdl:documentation>

            Realiza una firma digital delegada sobre un
            documento segun el estandard OASIS Digital Signature Service (DSS)
           </wsdl:documentation>


           <wsdlsoap:operation soapAction="urn:sign"/>

           <wsdl:input name="signRequest">

                <wsdlsoap:body use="literal"/>

           </wsdl:input>

           <wsdl:output name="signResponse">

                <wsdlsoap:body use="literal"/>

           </wsdl:output>

      </wsdl:operation>


      <wsdl:operation name="verify">

           <wsdl:documentation>

            Verifica una firma digital OASIS Digital
            Signature Service (DSS)
           </wsdl:documentation>


           <wsdlsoap:operation soapAction="urn:verify"/>

           <wsdl:input name="verifyRequest">

                <wsdlsoap:body use="literal"/>

           </wsdl:input>

           <wsdl:output name="verifyResponse">

                <wsdlsoap:body use="literal"/>

           </wsdl:output>

      </wsdl:operation>


      <wsdl:operation name="getSignConfiguration">

           <wsdl:documentation>

            Obtiene los certificados con los que una
            aplicacion en el MC de Firma Digital puede realizar
            una firma
           </wsdl:documentation>


           <wsdlsoap:operation soapAction="urn:getSignConfiguration"/>

           <wsdl:input name="getSignConfigurationRequest">

                <wsdlsoap:body use="literal"/>

           </wsdl:input>

           <wsdl:output name="getSignConfigurationResponse">

                <wsdlsoap:body use="literal"/>

           </wsdl:output>

      </wsdl:operation>


      <wsdl:operation name="getSignInfoFromDocument">

           <wsdl:documentation>

            Obtiene informacion de un fichero de firma
           </wsdl:documentation>


           <wsdlsoap:operation soapAction="urn:getSignInfoFromDocument"/>

           <wsdl:input name="getSignInfoFromDocumentRequest">

                <wsdlsoap:body use="literal"/>

           </wsdl:input>

           <wsdl:output name="getSignInfoFromDocumentResponse">

                <wsdlsoap:body use="literal"/>

           </wsdl:output>

      </wsdl:operation>


 </wsdl:binding>


 <wsdl:service name="EsignService">


      <wsdl:documentation>

        Servicio web de firma digital 
      </wsdl:documentation>


      <wsdl:port binding="impl:EsignServiceSoap11Binding" name="EsignServiceSoap11Port">


           <wsdlsoap:address location="http://someexternalsite.com"/>


      </wsdl:port>


 </wsdl:service>
Run Code Online (Sandbox Code Playgroud)

我已经下载了每个单独的.xsd关联并在公共服务器上发布它们,我也更改了schemaLocations,因此它们指向这个公共服务器上的地址,但是,问题似乎与WSDL结构有关.

Pet*_*dea 2

更新之前的主要问题肯定是你的语法错误。<schema xmlns="urn:oasis:names:tc:dss:1.0:core:schema">你所说的工具正在期待的地方<schema xmlns="http://www.w3.org/2001/XMLSchema">。要简单地导入外部 XSD 文件,上面的默认 XML 命名空间修复就足够了。

模式导入/包含可能非常混乱;对于这些情况,当人们将它们放入 WSDL 中时,正如您所建议的那样,很容易犯错误,因为这不是简单的剪切和粘贴的情况。例如,某些工具在处理最初基于 xsd:include 的引用时可能会出现问题;chameleon 包含无法在 WSDL 内复制;并且所有 xsd:import 不得使用 schemaLocation 属性。

要解决与损坏的引用相关的问题,我强烈建议使用 HTTP 调试器,例如 Fiddler。它至少会告诉您忘记清理哪些引用,或者您的模拟解决方案未正确设置的任何 HTTP 标头。

如果上述内容仍然给您留下一些疑问,您将必须发布修改后的 WSDL。