WCF服务调用返回空文件/页面

问题描述 投票:4回答:2

问题:当我调用部署的WCF服务时,浏览器会下载一个空的svc文件,但不会向我显示包含服务xml文件的页面。

上下文:我必须将托管WCF服务的webapp移动到新服务器。这个服务在运行IIS的旧服务器上运行良好。新服务器有2个Web服务器正在运行。 IIS 8.5和WAMP 2.5,因为服务器托管了Php应用程序和Jira。

设置:WAMP服务器侦听80端口,然后根据需要重定向到IIS,到特定端口。这是设置的示例。

Wamp配置(https-vhosts.config):

<VirtualHost *:80>    
ServerName site.de
ServerAlias www.site.de 
<Proxy *>
    Require all granted
</Proxy>

ProxyRequests           Off
ProxyPreserveHost       On
ProxyPass               /       http://localhost:9050/
ProxyPassReverse        /       http://localhost:9050/

服务网址:https://www.site.de/folder/service.svc

服务配置:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="someBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="52428899">
      <readerQuotas maxDepth="64" maxStringContentLength="81920" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>

  <serviceBehaviors>
    <behavior name="LargeServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <useRequestHeadersForMetadataAddress />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

<services>
  <service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
    <endpoint address="http://www.site.de/folder/service.svc" 
    binding="basicHttpBinding"
    bindingConfiguration="someBinding" 
    contract="ExampleServiceModels.IExampleService" />
  </service>
</services>

我之前从未使用过wamp。而且我对WCF设置也没有多少经验。任何想法或提示将受到高度赞赏。

编辑使用wcf测试客户端我得到这个:

Error: Cannot obtain Metadata from http://www.site.de/folder/ExampleService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://www.site.de/folder/ExampleService.svc Metadata contains a reference that cannot be resolved: 'http://www.site.de/folder/ExampleService.svc'. The requested service, 'http://www.site.de/folder/ExampleService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://www.site.de/folder/ExampleService.svc The document at the url http://www.site.de/folder/ExampleService.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:- Report from 'XML Schema' is 'Root element is missing.'.- Report from 'DISCO Document' is 'Root element is missing.'.- Report from 'WSDL Document' is 'There is an error in XML document (0, 0).'. - Root element is missing.
asp.net wcf iis wamp
2个回答
2
投票

您需要指定MEX(元数据交换)绑定以向您公开WSDL。示例(查看地址“mex”):

<service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
    <endpoint address="http://www.site.de/folder/service.svc" binding="basicHttpBinding"
         bindingConfiguration="someBinding" 
    contract="ExampleServiceModels.IExampleService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

要在浏览器中获取wsdl类型:https://www.site.de/folder/service.svc?wsdl


0
投票

不确定这个答案将在近3年后帮助OP。但它更适合@GothamLlianen。但是,如果要在HTTPS连接上访问WFC服务,则需要明确指定该绑定。

在Web.Config的<system.serviceModel>节点中添加它

<bindings>
  <webHttpBinding>
    <binding name="HttpsBinding">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </webHttpBinding>
</bindings>

然后将name添加到端点,在本例中为“HttpsBinding”

<endpoint bindingConfiguration="HttpsBinding"

以下完整节点供参考

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="MyProject.Api">
        <endpoint bindingConfiguration="HttpsBinding" address="" behaviorConfiguration="web" binding="webHttpBinding" contract="MyProject.IApi" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceAuthorization principalPermissionMode="UseAspNetRoles" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <bindings>
      <webHttpBinding>
        <binding name="HttpsBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
© www.soinside.com 2019 - 2024. All rights reserved.