代理的生成在一个环境中工作正常但在另一个环境中不工作?

时间:2013-05-15 12:14:04

标签: c# wcf web-services proxy wsdl

我在Windows服务(Selfhost)中托管了一个简单的Webserivce(WCF)。服务声明如下:

<service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration">
        <endpoint binding="basicHttpBinding" bindingConfiguration="BasicMyAppIntegration" bindingNamespace="MyApp.ServiceImplementation" contract="MyApp.ServiceContracts.IMyAppIntegration"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8008/MyAppServiceutv/Integration"/>
          </baseAddresses>
        </host>
      </service>

我可以用这个URL浏览WSDL:

http://localhost:8008/MyAppServiceutv/Integration?wsdl

在Visual Studio 2012中添加服务引用时,我得到以下异常:

异常

该文件已被理解,但无法处理。

  • WSDL文档包含无法解析的链接。
  • 下载“http://localhost:8008/MyAppServiceutv/Integration?xsd=xsd0”时出错。
  • 无法连接到远程服务器

元数据包含无法解析的引用:“http://MyComputer:8008/MyAppServiceutv/Integration?wsdl”。 内容类型application / soap + xml;服务http://MyComputer:8008/MyAppServiceutv/Integration?wsdl不支持charset = utf-8。客户端和服务绑定可能不匹配。 远程服务器返回错误:(415)无法处理消息,因为内容类型为'application / soap + xml; charset = utf-8'不是预期的类型'text / xml;字符集= UTF-8' .. 如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。

迁移到开发环境

将服务移动到开发计算机时,一切都很好吗?为什么我会在一个环境中遇到上述问题?这可能是由于强大的安全限制吗?

1 个答案:

答案 0 :(得分:0)

听起来您的VS2012实例已从服务主机中脱机。尝试更改您的配置......

  <service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration">
    <endpoint binding="basicHttpBinding" bindingConfiguration="BasicMyAppIntegration" bindingNamespace="MyApp.ServiceImplementation" contract="MyApp.ServiceContracts.IMyAppIntegration"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://{my fully qualified domain name}:8008/MyAppServiceutv/Integration"/>
      </baseAddresses>
    </host>
  </service>

好。现在我已经确认了这个问题......一个解释。 .net 4.0或更少WCF生成多文件WSDL文件。基本WSDL文件链接到各种文件。 WDSL文件中的链接使用绝对URI而不是相对URI链接到其他文件。因此,当您的Visual Studio尝试查找其他WDSL文件时,它无法在“localhost”上找到它。

使用.net 4.5 WCF可以生成单个文件WSDL,这也可以解决您的问题。但总的来说,在我看来,在处理WSDL代理生成时WCF 4.0已经崩溃了。

相关问题