简体   繁体   English

具有多个服务和合同的WCF网站

[英]WCF Site with multiple services and contracts

I am running into an issue trying to host two services on the same site. 我在尝试在同一站点上托管两个服务时遇到问题。 They have the same base uri, but different services names, and each has its own contract. 它们具有相同的基本uri,但服务名称不同,并且每个都有其自己的合同。

While testing in my VS environment (IIS 7.5) everything works fine. 在我的VS环境(IIS 7.5)中进行测试时,一切正常。 However when I deploy to a server (IIS 8.5), both uri's are showing the same wsdl for some reason. 但是,当我部署到服务器(IIS 8.5)时,由于某些原因,两个uri都显示相同的wsdl。 It seems like the contract for the second service is ignored. 似乎第二项服务的合同已被忽略。

There are two different .svc files with code behind. 有两个不同的.svc文件,后面都有代码。 (all names have been changed to protect the innocent.) (所有名称均已更改,以保护无辜者。)

sites: 网站:

https://mysite/services/Service1.svc https://mysite/services/Service1.svc

https://mysite/services/Service2.svc https://mysite/services/Service2.svc

Here is my config: 这是我的配置:

<services>      
  <service name="Service1" behaviorConfiguration="DefaultBehavior">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" contract="Namespace.IService1"/>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>        
  </service>
   <service name="Service2" behaviorConfiguration="DefaultBehavior">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" contract="Namespace.IService2"/>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>        
  </service>
</services> 

<bindings>
    <wsHttpBinding>
        <binding name="DefaultBinding" receiveTimeout="00:05:00" 
                sendTimeout="00:05:00" bypassProxyOnLocal="false" transactionFlow="false" 
                hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" 
                maxReceivedMessageSize="2147483647" messageEncoding="Mtom" 
                textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
              <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <reliableSession ordered="true" inactivityTimeout="00:5:00" enabled="false"/>
              <security mode="Transport">
                <transport clientCredentialType="None" />
              </security>
        </binding>
    <wsHttpBinding>
<bindings>

<serviceBehaviors>
    <behavior name="DefaultBehavior">
    <serviceMetadata httpsGetEnabled="true"  httpsGetBindingConfiguration="true" />
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <serviceThrottling maxConcurrentCalls="160" maxConcurrentInstances="160" maxConcurrentSessions="100" /> 
    </behavior>
</serviceBehaviors>

The problem is that both sites are reflecting the same WSDL, ie same methods for contract="Namespace.IService1" Any ideas on what is going on here to cause this? 问题在于两个站点都反映相同的WSDL,即contract="Namespace.IService1"相同方法。有关导致这种情况的任何想法?

I believe the problem is because they both have the same address. 我相信问题是因为他们都有相同的地址。 How can the server distinguish if your intent is to call Service1 or Service2 ? 服务器如何区分您的意图是调用Service1还是Service2

While keeping the same base URI try to change their address 在保持相同的基本URI的同时尝试更改其地址

Unfortunately, WCF doesn't really have a good way to handle this use case. 不幸的是,WCF并没有一个很好的方法来处理此用例。 You can't have two contracts on the same endpoint 同一端点上不能有两个合约

The address for the endpoint for Service1 Service1端点的地址

<endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" contract="Namespace.IService1"/>

The address must be different from that of Service2 该地址必须与Service2的地址不同

    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" contract="Namespace.IService2"/>

It actually turned out to be something stupid, an xcopy error. 实际上,事实证明这是愚蠢的,xcopy错误。 My xcopy script for the new additional service was copied and pasted from the original service, but I forgot to rename the .svc source to the new service name. 我的新附加服务的xcopy脚本是从原始服务复制并粘贴的,但是我忘了将.svc源重命名为新服务名称。 So it copied the same .svc to two different files. 因此,它将相同的.svc复制到两个不同的文件。

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

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