WCF无法找到端点配置问题

时间:2012-02-06 19:35:36

标签: c# wcf configuration wcf-binding wcf-client

我有一个使用WCF的web服务我正在我的本地机器上测试,它给了我一个头脑分析师。

我的服务配置如下:

<system.serviceModel>
   <services>
      <service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" 
               behaviorConfiguration="DatroseServiceBehavior">
         <endpoint 
             address="mex"
             binding="basicHttpBinding" 
             contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
      </service>
   </services>
   <behaviors>
      <serviceBehaviors>
         <behavior name="DatroseServiceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
         </behavior>
      </serviceBehaviors>
   </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我的客户端配置如下:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="BasicHttpBinding_IDatroseService" 
             closeTimeout="00:02:00" openTimeout="00:01:00" 
             receiveTimeout="00:10:00" sendTimeout="00:02:00"
             allowCookies="false" bypassProxyOnLocal="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="524288" maxBufferPoolSize="524288" 
             maxReceivedMessageSize="524288" 
             messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
             useDefaultWebProxy="true">
            <readerQuotas 
                 maxDepth="32" maxStringContentLength="524288" 
                 maxArrayLength="524288" maxBytesPerRead="524288" 
                 maxNameTableCharCount="524288" />
            <security mode="None">
                 <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                 <message clientCredentialType="UserName" algorithmSuite="Default" />
            </security>
         </binding>
      </basicHttpBinding>
   </bindings>
   <client>
       <endpoint name="BasicHttpBinding_IDatroseService"
           address="http://localhost/DatroseWCFService/DatroseService.svc"  
           behaviorConfiguration="DatroseServiceBehavior"
           binding="basicHttpBinding"  
           bindingConfiguration="BasicHttpBinding_IDatroseService"
           contract="DatroseWCFService.IDatroseService"  />
   </client>
   <behaviors>
      <endpointBehaviors>
         <behavior name="DatroseServiceBehavior">
             <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
         </behavior>
      </endpointBehaviors>
   </behaviors>
 </system.serviceModel>

我收到的错误是:

  

http://localhost/DatroseWCFService/DatroseService.svc没有端点可以监听   接受消息。这通常是由不正确的地址或   SOAP动作。有关更多详细信息,请参阅InnerException(如果存在)。

...然而,如果我浏览到我获得服务屏幕的位置,那么它似乎已正确设置。

我确定这与我的端点配置有关,但我无法弄清楚它们应该是什么样子。这里会有一些帮助。

UPDATE whups我输错了错误信息。现在已修复。

更新2 根据我认为在这些回复中建议我已将服务器配置更改为:

<system.serviceModel>
   <services>
      <service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" 
               behaviorConfiguration="DatroseServiceBehavior">
         <endpoint 
             address="/svc"
             binding="basicHttpBinding"
             contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService"  />
         <endpoint 
             address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
   </services>
   <behaviors>
       <serviceBehaviors>
          <behavior name="DatroseServiceBehavior">
             <serviceMetadata httpGetEnabled="true"/>
             <serviceDebug includeExceptionDetailInFaults="true"/>
             <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          </behavior>
       </serviceBehaviors>
   </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我的客户端配置为:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="BasicHttpBinding_IDatroseService" 
             closeTimeout="00:02:00" openTimeout="00:01:00" 
             receiveTimeout="00:10:00" sendTimeout="00:02:00"
             allowCookies="false" bypassProxyOnLocal="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="524288" maxBufferPoolSize="524288" 
             maxReceivedMessageSize="524288"
             messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
             useDefaultWebProxy="true">
          <readerQuotas 
              maxDepth="32" maxStringContentLength="524288" maxArrayLength="524288"
              maxBytesPerRead="524288" maxNameTableCharCount="524288" />
          <security mode="None">
              <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
              <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
       </binding>
     </basicHttpBinding>
   </bindings>
   <client>
      <endpoint name="BasicHttpBinding_IDatroseService" 
          address="http://localhost/DatroseWCFService/DatroseService.svc/svc" 
          behaviorConfiguration="DatroseServiceBehavior"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_IDatroseService"
          contract="DatroseWCFService.IDatroseService" />
   </client>
   <behaviors>
      <endpointBehaviors>
         <behavior name="DatroseServiceBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
         </behavior>
      </endpointBehaviors>
   </behaviors>
</system.serviceModel>

当我运行这个时,我现在得到一个400(错误的请求)错误。我不确定这是前进还是后退。我是否创建了一个新问题,或者我是否已经清除了下一个问题?

更新3

根据niao的建议,我改为使用服务器配置:

<system.serviceModel>
    <services>
        <service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" behaviorConfiguration="DatroseServiceBehavior">
            <endpoint contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" binding="basicHttpBinding" address="http://localhost/DatroseWCFService/DatroseService.svc"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="DatroseServiceBehavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

...然而,当我浏览这个地址时,我得到了一个黄色的死亡屏幕:

     当'system.serviceModel / serviceHostingEnvironment / multipleSiteBindingsEnabled'时   在配置中设置为true,端点需要指定   相对地址。如果要指定相对的listen URI   端点,那么地址可以是绝对的。要解决这个问题,   为端点指定相对uri   。的 'http://localhost/DatroseWCFService/DatroseService.svc'

......所以,我试着把它变成一条相对的路径:

<endpoint 
   address="localhost/DatroseWCFService/DatroseService.svc"
   binding="basicHttpBinding" 
   contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />

...但在发布之后,我收到404错误。客户端端点配置如下:

<endpoint name="BasicHttpBinding_IDatroseService"
    address="http://localhost/DatroseWCFService/DatroseService.svc" 
    behaviorConfiguration="DatroseServiceBehavior"
    binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IDatroseService"
    contract="DatroseWCFService.IDatroseService"  />

更新4 根据marc_s的建议,我从客户端删除了绑定配置,所以我的配置如下所示:

<system.serviceModel>
    <client>
        <endpoint address="http://localhost/DatroseWCFService/DatroseService.svc" behaviorConfiguration="DatroseServiceBehavior"
         binding="basicHttpBinding" 
         contract="DatroseWCFService.IDatroseService" name="BasicHttpBinding_IDatroseService" />
    </client>
    <behaviors>
        <endpointBehaviors>
            <behavior name="DatroseServiceBehavior">
                <dataContractSerializer maxItemsInObjectGraph="10000000"/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>

我的服务器配置如下:

<system.serviceModel>
    <services>
        <service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" behaviorConfiguration="DatroseServiceBehavior">
            <endpoint contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" binding="basicHttpBinding" address=""/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="DatroseServiceBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true" httpHelpPageEnabled="true"/>
                <dataContractSerializer maxItemsInObjectGraph="10000000"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我不再收到404错误。

但是,我确实得到了一个400(ProtocolException,Bad Request),没有关于它得到的内容或为什么它不好的教化信息。我希望我已经超越了端点问题,进入了全新的服务配置空间。

更新5

每个请求,我服务的“骨架”(我假设界面会这样做?):

[ServiceContract]
public interface IDatroseService
{

    [OperationContract]
    bool SubmitPayableTransaction(List<InvoiceItem> invoices);

    [OperationContract]
    Dictionary<string, bool> ValidateAccounts(List<string> accounts);

    [OperationContract]
    Dictionary<string, int> GetVendor1099Types(List<string> vendors);

    [OperationContract]
    Dictionary<string, string> GetPaymentTerms(List<string> vendors);

}

1 个答案:

答案 0 :(得分:16)

所以我假设你的服务是在IIS中托管的,对吧?

因此,*.svc生活的虚拟目录基本上定义了您的服务地址 - 这个地址是否正确?

另外:您在服务端点上有“{1}}的”相对“地址

mex

我认为这是一个非常糟糕的主意 - MEX代表元数据交换,我会将该地址用于常规服务端点!它只是违反了最少的原则 - 如果端点称为 <endpoint address="mex" ,我希望 BE 是元数据交换端点 - 而不是常规服务端点...... )< / p>

无论如何 - 使用该常规地址,您的完整服务地址将变为:

MEX

如果您在该地址上拨打您的服务怎么办?您收到回复了吗?

<击> 更新:不确定您是如何尝试测试此内容的。这是一个SOAP Web服务 - 您将在浏览器中看到服务的“登录页面”(“帮助”页面),但要测试服务本身,您需要使用支持SOAP的测试工具(如{{ 3}}或WCF Test Client) - 您无法通过浏览其Web地址来测试SOAP Web服务。
好的,所以你通过从测试应用程序调用服务来测试它 - 这应该肯定有效!

更新#2:,因为您在IIS中托管它(对吗?),您的服务地址基本上由* .svc文件所在的虚拟目录定义。所以我的下一次尝试是:只需将该地址作为您的服务地址。

服务端配置更改为:

http://yourserver/DatroseWCFService/DatroseService.svc/mex

以及客户端配置

<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService" 
         behaviorConfiguration="DatroseServiceBehavior">
   <endpoint 
       address=""   <!-- define nothing here - just let the *.svc file determine your service address -->
       binding="basicHttpBinding" 
       contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
   <endpoint 
       address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

这有用吗?

下一次尝试是使用没有<endpoint name="BasicHttpBinding_IDatroseService" address="http://localhost/DatroseWCFService/DatroseService.svc" behaviorConfiguration="DatroseServiceBehavior" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDatroseService" contract="DatroseWCFService.IDatroseService" /> 值的客户端配置 - 因为这也是你在服务器上所做的事情 - 只是没有bindingConfiguration= >任何修改 - 这有效吗??