2010-10-04 48 views
1

我正尝试使用WCF构建Web服务。由于该服务最终将被非.NET语言使用,因此我一直试图使用“添加Web引用”或使用WSDL.exe而不是svcutil方式对其进行测试。我一直在收到以下错误:WCF Web服务 - 无法构建代理类

从WSDL.exe - 错误:无法从命名空间http://tempuri.org导入绑定BasicHttpBinding_IEchoService。 - - 无法导入操作Echo。 - - 元素http://tempuri.org/:Echo缺失。

从添加服务引用和添加Web引用: 元数据包含无法解析的引用:链接到wsdl。 WSDL文档包含无法解析的链接。下载时出现错误http://localhost:8080/EchoService.svc?xsd=xsd0 底层连接已关闭。

此简化示例与主要服务具有相同的问题。

这里的服务的Web.Config:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="EchoBehaviorConfiguration"> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="EchoService"> 
     <endpoint address="" 
        behaviorConfiguration="EchoBehaviorConfiguration" 
        binding="basicHttpBinding" 
        contract="IEchoService" /> 
     <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" /> 

     </service> 
    </services> 
    <bindings> 
     <basicHttpBinding> 
     </basicHttpBinding> 
     <mexHttpBinding></mexHttpBinding> 
    </bindings> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

这里的合同/接口:

[ServiceContract] 
public interface IEchoService 
{ 
    [OperationContract] 
    string Echo(string message); 
} 

而这里所生成的WSDL:

<wsdl:definitions name="EchoService" targetNamespace="http://tempuri.org/"> 
<wsdl:types> 
<xsd:schema targetNamespace="http://tempuri.org/Imports"> 
<xsd:import schemaLocation="http://localhost:8080/EchoService.svc?xsd=xsd0" namespace="http://tempuri.org/"/> 
<xsd:import schemaLocation="http://localhost:8080/EchoService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/> 
</xsd:schema> 
</wsdl:types> 
<wsdl:message name="IEchoService_Echo_InputMessage"> 
<wsdl:part name="parameters" element="tns:Echo"/> 
</wsdl:message> 
<wsdl:message name="IEchoService_Echo_OutputMessage"> 
<wsdl:part name="parameters" element="tns:EchoResponse"/> 
</wsdl:message> 
<wsdl:portType name="IEchoService"> 
<wsdl:operation name="Echo"> 
<wsdl:input wsaw:Action="http://tempuri.org/IEchoService/Echo" message="tns:IEchoService_Echo_InputMessage"/> 
<wsdl:output wsaw:Action="http://tempuri.org/IEchoService/EchoResponse" message="tns:IEchoService_Echo_OutputMessage"/> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="BasicHttpBinding_IEchoService" type="tns:IEchoService"> 
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="Echo"> 
<soap:operation soapAction="http://tempuri.org/IEchoService/Echo" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="EchoService"> 
<wsdl:port name="BasicHttpBinding_IEchoService" binding="tns:BasicHttpBinding_IEchoService"> 
<soap:address location="http://localhost:8080/EchoService.svc"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

该服务目前通过IIS7在本地托管。我尝试了HTTP和HTTPS,并有相同的问题。如果我试图改变从basicHttpBinding到webHttpBinding的绑定,WSDL中没有任何变化。

关于我要去哪里的任何想法都是错误的?

更新: 我有配置现在设置,如果该服务运行在卡西尼而不是IIS下,我可以添加服务或Web引用到我的测试项目。我不能保存wsdl并使用WSDL.exe来生成代理类。

所以现在我有3个问题:

  1. 除了做一个ASPNET_REGIIS安装和使用IIS注册WCF 4,有什么事我可以有什么关系?

  2. 任何想法我需要做什么才能使它与WSDL.exe一起工作?

  3. 执行ASMX服务并比较生成的WSDL后,它们会有很大的不同,这让我质疑WCF在这一点上与非.NET语言的兼容性。

回答

3

由于在WSDL中使用了?xsd = xsd0,所以我遇到了同样的问题。我发现这个链接,给出了这样的解决方案:

  • 当你释放你的武器(进程监视器)对csc.exe进程(这是编译器生成的XSD),你会意识到,IIS身份IIS_WPG不有权访问Windows \ Temp文件夹。给文件夹足够的权利,并解决中提琴问题。

http://merill.net/2008/04/wcf-add-service-reference-gotcha-with-windows-server/

+0

+1这是我的问题。干杯! – ashes999 2011-11-04 14:15:44

0

给出你的例子,我认为你可以简化你的配置。

例如,如果你有。SVC文件,它看起来像你的WSDL的enpoint声明,你可以有:

<system.serviceModel> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

,那么你应该能够通过URL http://localhost:8080/EchoService.svc(假设它是在本地计算机上,并监听端口8080进行访问。只是想,有时,Tomcat使用8080作为其默认端口....)

+0

我试过了,它仍然是行不通的。它产生相同的错误信息。在上面的例子中,我有serviceMetadata和serviceDebut,但是SO似乎不会为我的生活显示它。 – JamesEggers 2010-10-04 16:03:42

+0

如果您在浏览器中键入http:// localhost:8080/EchoService.svc,假设IIS与您的服务一起运行(并且它正在侦听端口8080),会发生什么情况? – 2010-10-04 16:55:38

+0

当服务通过IIS托管时,我可以在浏览器中查看wsdl。 – JamesEggers 2010-10-04 18:29:47

1

看起来你没有在正确的位置

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.aspx

的结果是所指定的行为名httpGet未启用元数据。

+0

改变之后,我现在得到一个错误,说application/soap + xml的内容类型不是预期的类型text/xml。 – JamesEggers 2010-10-04 16:06:32

+0

这是否是相反的方式,预计是肥皂,你有文字?如果是这样,您可能会收到错误消息而不是合同。 – 2010-10-04 17:12:01

+0

是的,我收到了一条错误消息。我只是不知道如何解决这个问题,因为我使用basicHttpBinding。 远程服务器返回错误:(415)由于内容类型'application/soap + xml; charset = utf-8'不是预期的类型'text/xml;字符集= UTF-8' 。 – JamesEggers 2010-10-04 18:34:44