【问题标题】:Generation of proxy works fine in one environment but not in the other?代理的生成在一种环境中可以正常工作,但在另一种环境中却不行?
【发布时间】:2013-05-15 12:14:04
【问题描述】:

我有一个简单的 Web 服务 (WCF) 托管在 Windows 服务 (Selfhost) 中。服务的声明如下所示:

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

迁移到开发环境

将服务移至开发计算机时,一切正常吗?为什么我会在一个环境中遇到上述问题?这可能是由于严格的安全限制造成的吗?

【问题讨论】:

  • 服务是否在 Cassini 中运行?如果是这样,它不能从不同的机器调用,你需要将它发布到 iis
  • 否 服务作为 Windows 服务自托管。在开发计算机上生成代理没有问题,但是当将其全部移动到这个更安全的环境时,它就不行了吗?
  • 8008 端口是否配置为接受流量?您可能需要从 VS.NET 2010 命令提示符使用此命令,如下所示:netsh http add urlacl url=http://+:8008/user=\everyone.
  • @Rajesh 这可能是它,你的意思是我可以通过键入该行直接从 Visual Studio 2010 GUI 设置正确的权限吗?我会试试这个。
  • 在命令提示符下完成

标签: c# wcf web-services proxy wsdl


【解决方案1】:

听起来您的 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 可以生成 SINGLE FILE WSDL,这也将解决您的问题。但总体而言,我认为 WCF 4.0 在处理 WSDL 代理生成时被破坏了。

【讨论】:

  • 是的,在这个失败的环境中,服务被放置在服务器上。你的意思是不能在这个服务器上使用 localhost 吗?为什么它在所有其他环境中都能如此出色,而在这个环境中却不行?
猜你喜欢
  • 2019-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
相关资源
最近更新 更多