1

我创建了一个 RESTful WCF 服务(感谢 StackOverflow)。我创建了一个测试客户端,它是一个简单的 .aspx 页面,带有 5 个文本框和一个提交按钮。当我在文本框中输入数据并单击提交按钮时,它会将数据提交到 WCF 服务。

我的 WCF 服务在 Visual Studio 开发服务器下运行并且运行良好,我能够成功地将数据发送到 WCF 服务。今天我在本地 IIS 上部署了这个 WCF 服务。当我尝试在客户端应用程序(.aspx 页面)中引用服务 URL 时,我收到此错误。

“元数据包含无法解析的引用。客户端和服务绑定可能不匹配。无法处理消息,因为内容类型 'application/soap+xml; charset=utf-8' 不是预期的类型 'text/xml; "

知道问题可能是什么吗?这是我的 web.config

    <?xml version="1.0"?>
    <configuration> 
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>   
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>

        <services>
          <service name="RESTService1">
            <endpoint address="http://localhost:420/WCFRESTService100/RESTService1.svc" binding="webHttpBinding" name="MainHttpPoint" contract="RESTService1" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:420/WCFRESTService100/RESTService1.svc" />
              </baseAddresses>
            </host>
          </service>
        </services>

        <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>

    </configuration>
4

1 回答 1

1

我认为问题在于您完全为 REST 服务添加了服务引用。REST 服务没有任何可用的元数据,因为没有用于描述它们的标准元数据格式。

您能够添加服务引用的唯一原因是因为您离开了服务,该服务公开了一个 SOAP 定义。因此,如果您粘贴客户端配置,我确定端点有一个 SOAP 端点(wsHttpBinding 或 basicHttpBinding),因此您在拨打电话时收到有关 mime 类型不匹配的错误的原因。

如果要使用 WCF 从客户端调用 REST 服务,则需要在客户端和服务器之间共享合同定义,或者在客户端完全复制它。

于 2011-07-31T23:26:19.093 回答