无法添加 Web 引用。

3

我正在尝试在Visual Studio 2010中使用C#的SOAP服务。我尝试了新建服务引用,但总是出现以下错误:

自定义工具错误:无法为服务引用“easyZM”生成代码。请检查其他错误和警告消息以获取详细信息。路径\Service References\serviceTest\Reference.svcmap

并伴随着以下警告:

警告13:自定义工具警告:无法导入wsdl:portType

详情:运行WSDL导入扩展时抛出了异常:System.ServiceModel.Description.DataContractSerializerMessageContractImporter

错误:找不到http://schemas.xmlsoap.org/wsdl/:putDkm的定义。缺少命名空间为http://schemas.xmlsoap.org/wsdl/的服务描述。

参数名称:名称

错误源XPath://wsdl:definitions[@targetNamespace='urn:Easy']/wsdl:portType[@name='EasyPort'] 路径\Service References\serviceTest\Reference.svcmap

我不知道该怎么办。我看过这个问题What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType",但那里提供的解决方案都对我无效。

wsdl文件路径:https://ews.zav-mb.si/easy/wsdl/easy.wsdl

有什么想法吗?

还可以让其他人尝试并报告结果吗?

我发现问题很可能出在wsdl文件本身。但我不知道该如何修复它。

<definitions xmlns:tns="urn:Easy" 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="Easy" targetNamespace="urn:Easy">
<types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Hello">
    <xsd:element name="fileName" type="xsd:string"/>
    <xsd:element name="fileContent" type="xsd:string"/>
    <xsd:element name="fileSize" type="xsd:int"/>
    <xsd:element name="easyDocRef" type="xsd:string"/>
    <xsd:element name="message" type="xsd:string"/>
    <xsd:element name="result" type="xsd:boolean"/>
    </xsd:schema>
</types>

<message name="putDkm">
    <part name="fileName" type="tns:fileName"/>
    <part name="fileContentBase64Encoded" type="tns:fileContent"/>
    <part name="fileSize" type="tns:fileSize"/>
</message>
<message name="putDkmResponse">
    <part name="result" type="tns:result"/>
    <part name="message" type="tns:message"/>
    <part name="easyDocref" type="tns:easyDocRef"/>
</message>
<!--  get stuff  -->
<message name="get">
    <part name="easyDocRef" type="tns:getEasyDocRef"/>
</message>
<message name="getResponse">
    <part name="result" type="tns:result"/>
    <part name="message" type="tns:message"/>
    <part name="fileContentBase64Encoded" type="tns:fileContent"/>
    <part name="fileName" type="tns:fileName"/>
</message>
<portType name="EasyPort">
    <operation name="putDkm">
        <input message="putDkm"/>
        <output message="tns:putDkmResponse"/>
    </operation>
    <operation name="get">
        <input message="get"/>
        <output message="tns:getResponse"/>
    </operation>
</portType>
<binding name="EasyBinding" type="tns:EasyPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="putDkm">
        <soap:operation soapAction="urn:putDkmAction"/>
        <input>
            <soap:body use="encoded" namespace="urn:Easy" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
            <soap:body use="encoded" namespace="urn:Easy" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
    </operation>
    <operation name="get">
        <soap:operation soapAction="urn:getAction"/>
        <input>
            <soap:body use="encoded" namespace="urn:Easy" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
            <soap:body use="encoded" namespace="urn:Easy" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
    </operation>
</binding>
<service name="EasyService">
    <port name="EasyPort" binding="tns:EasyBinding">
        <soap:address location="https://ews.zav-mb.si/easy/index.php"/>
    </port>
</service>
</definitions>

这还是最新的吗?我刚刚在VS 2010中添加了一个https://ews.zav-mb.si/easy/wsdl/easy.wsdl的服务引用,没有任何问题... - AVee
你能否报告一下你是如何做到的?我设法通过黑客方式完成了,但是这是一条艰难的道路。 - gabrjan
你是否将项目设置为针对客户端框架?例如.NET Framework 4.0 Client? - Brannon
现在我正在针对3.5框架进行开发。 - gabrjan
你负责创建这个服务吗?我发现,添加一个包含你的服务支持的接口的程序集会更容易。添加一个契约程序集,并自己创建到服务的连接。就个人而言,我不喜欢添加服务引用。 - Aran Mulholland
我发现问题可能出在wsdl文件本身。但是我不知道如何修复它。不,你没有做错任何事。这是wsdl提供者需要修复的。 - I4V
3个回答

1
肯定是WSDL出了问题。 我也遇到了同样的警告。然后我进行了修改。
<portType name="EasyPort">
    <operation name="putDkm">
        <input message="putDkm"/>
        <output message="tns:putDkmResponse"/>
    </operation>
    <operation name="get">
        <input message="get"/>
        <output message="tns:getResponse"/>
    </operation>
</portType>

<portType name="EasyPort">
    <operation name="putDkm">
        <input message="tns:putDkm"/>
        <output message="tns:putDkmResponse"/>
    </operation>
    <operation name="get">
        <input message="tns:get"/>
        <output message="tns:getResponse"/>
    </operation>
</portType>

(请查看命名空间) 之后编译成功,但是没有生成任何客户端代码。 我不打算修复所有问题,但我建议您首先创建一个具有相同接口的服务原型,生成其WSDL,并将结果与您目前拥有的内容进行比较。


我最终通过提供一些数据说服Web服务的创建者开始修复它。所以谢谢你! - gabrjan

0

我在我的项目中曾经遇到过同样的问题,显然问题出在参考文件所在的文件夹只读属性上。因此文件无法被覆盖,您可以尝试去除该文件夹的只读属性以及整个项目的只读属性,然后重新打开解决方案。这样应该就能成功生成了。


0

不知道你是否已经解决了这个问题:(

我尝试使用svcutil.exe为服务生成代理类,但是代理没有生成,反而出现了一些错误。下面是我在控制台上得到的错误信息。 enter image description here 我百分之百相信,这是服务本身的问题,因为在另一篇帖子中发现了一个类似的问题,通过修改服务来解决。请检查服务中的代码,你肯定能够解决这个问题。

Add Service Reference error “Cannot import wsdl:portType


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接