2011-09-20 40 views
4

我有一个提供两个接口的Web服务。一个是“MyAppNameData”,另一个是“MyAppNameSync”。我将两个服务引用添加到WPF应用程序。在代码中,当我使用“MyAppNameData”引用时,我不会收到错误。当我使用产生“MyAppNameSync”以下错误:提供两个接口的Web服务导致WPF应用程序出错

Could not find default endpoint element that references contract 'MyAppNameSync.IMyAppNameSync' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 

我加了两个引用的方式不尽相同,但是,使用带有WsHttpBinding的加入basicHttpBinding的和MyAppNameSync加入MyAppNameData。我不知道为什么是这样。

这是客户端的app.config文件中的serviceModel元素。正如你所看到的,是引用了合同中的端点元素“MyAppNameSync.IMyAppNameSync”,违背了错误信息说什么:

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IMyAppNameData" 
       closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" 
       sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" 
       maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" 
       transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
       maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <security mode="None"> 
       <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
       <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IMyAppNameSync" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" transactionFlow="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
       maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Message"> 
        <transport clientCredentialType="Windows" 
        proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="Windows" 
        negotiateServiceCredential="true" 
         algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://computername.domainname.home/MyAppNameSyncService/MyAppNameData.svc" 
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IMyAppNameData" 
      contract="MyAppNameData.IMyAppNameData" 
      name="BasicHttpBinding_IMyAppNameData" /> 
     <endpoint address="http://computername.domainname.home/MyAppNameSyncService/MyAppNameSync.svc" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyAppNameSync" 
      contract="MyAppNameSync.IMyAppNameSync" 
      name="WSHttpBinding_IMyAppNameSync"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
    </client>  
</system.serviceModel> 

任何建议将真正理解。

谢谢

+0

你是用同样的方法添加两个引用是什么意思?你应该只需要添加一个引用,它应该创建两个代理。 –

+0

感谢您的回复。我发布的Web服务中有两个.svc文件。 MyAppNameData.svc和MyAppNameSync.svc。要添加服务引用,我右键单击服务引用节点,选择添加,其中一个svc文件,为其命名空间名称,然后单击确定。我再次为其他svc文件做同样的事情。 – rogdawg

+0

好的,我很抱歉,我以为你有两个端点的单一服务,但你有两个无关的服务。 –

回答

2

好的。我现在正在工作。我显然在同一时间有几个错误。正如雷切尔在她上面的评论中所建议的,我试图找到一个最简单的案例。但是,最初是无法。从主机中删除一个服务,所以我只有MyAppNameData.svc没有,最初,工作。我知道过去的web服务的简单版本,所以我试图让所有的东西都回到那个工作点。

我用我的一个现有的ASP.NET Web应用程序指向我一直用于测试的Web服务的实例,并且我能够让它工作(即使有两个服务; MyAppNameData。主机MyAppNameWebService中的svc和MyAppNameSync.svc)。所以,我知道问题出在我的WPF应用程序和Web服务之间。

我曾经看过几个讨论主题,声明“如果您在类库中调用该服务并从另一个项目调用该类库,则会出现此错误”。但是,我认为在解决问题的步骤中我已经解决了这个问题。但是,当我将WPF项目中的所有内容全部剥离并重建(第100次)时,确保“将WS配置设置包含在主项目app.config中,如果它的winapp或web.config网络应用程序“,如 this thread中所述,我能够得到它的工作!

我曾尝试过这种解决方案,但显然我还没有解决一些其他问题。我不再收到错误,并且能够连接并使用来自同一主机的两个独立服务。所以,我在做生意。

谢谢大家的回复和建议。现在,迎接其他挑战!

相关问题