简体   繁体   English

WCF服务参考无法正常工作?

[英]WCF Service Reference not working?

I have created a RESTful WCF service (thanks to StackOverflow). 我已经创建了一个RESTful WCF服务(感谢StackOverflow)。 I have created a test client, it's a simple .aspx page with 5 textboxes and a submit button. 我创建了一个测试客户端,它是一个带有5个文本框和一个提交按钮的简单.aspx页面。 When I enter the data into the textboxes and click on the Submit button it will submit the data to the WCF service. 当我在文本框中输入数据并单击Submit按钮时,它将把数据提交到WCF服务。

My WCF service is running under Visual Studio development server and it worked fine, I am able to send data successfully to WCF service. 我的WCF服务在Visual Studio开发服务器下运行,并且运行良好,我能够将数据成功发送到WCF服务。 Today I deployed this WCF Service on my local IIS. 今天,我在本地IIS上部署了此WCF服务。 When I am trying to reference the Service URL in client application (.aspx page), I am getting this error. 当我尝试在客户端应用程序(.aspx页)中引用服务URL时,出现此错误。

"Metadata contains a reference that cannot be resolved. The client and service bindings may be mismatched. Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml;" “元数据包含无法解析的引用。客户端和服务绑定可能不匹配。由于内容类型'application / soap + xml; charset = utf-8'不是预期的类型'text / xml,因此无法处理消息。 ”

Any idea what the problem could be? 知道可能是什么问题吗? Here is my web.config 这是我的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>

I think the problem is that you've added a service reference at all for a REST service. 我认为问题在于您根本没有为REST服务添加服务引用。 REST services do not have any metadata available because there is no standard metadata format for describing them. REST服务没有任何可用的元数据,因为没有用于描述它们的标准元数据格式。

The only reason you were able to add a service reference is because you left on your service which exposed a SOAP definition for it. 能够添加服务引用的唯一原因是因为您留在服务上,该服务公开了它的SOAP定义。 So, if you paste your client config I'm sure the endpoint there is a SOAP endpoint (wsHttpBinding or basicHttpBinding) hence the reason you get the error about the mime-type mismatch when you make the call. 因此,如果粘贴您的客户端配置,我确定该端点存在一个SOAP端点(wsHttpBinding或basicHttpBinding),因此您在进行调用时会收到有关mime类型不匹配的错误的原因。

If you want to call the REST service from the client using WCF, you would either need to share the contract definition between client and server or completely duplicate it at the client. 如果要使用WCF从客户端调用REST服务,则需要在客户端和服务器之间共享合同定义,或者在客户端完全复制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM