c# WPF和WCF映射问题

发布于 2024-10-08 04:28:49 字数 3957 浏览 3 评论 0原文

我实际上正在尝试创建一个通过服务引用连接到 WCF 的 wpf 项目,我还在我的 wpf 项目中使用 MVVM 模式,当我在 viewModel 的 CTOR 中声明 serviceManager 时遇到问题!

我的 view.xaml 告诉我: 在 ServiceModel 客户端配置部分中找不到引用协定“UserServiceReferences.IUserManagement”的默认端点元素。这可能是因为找不到应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

这是我的 App.config 文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IUserManagement" 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>
        </bindings>
        <client>
            <endpoint address="http://localhost:2981/UserManagement.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserManagement"
                contract="UserServiceReference.IUserManagement" name="BasicHttpBinding_IUserManagement" />
        </client>
    </system.serviceModel>
</configuration>

这是我的 WCF 服务中的 Web.config:

<?xml version="1.0"?>
<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
    </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- Pour éviter la divulgation des informations sur les métadonnées, définissez la valeur ci-dessous sur false et supprimez le point de terminaison des métadonnées ci-dessus avant le déploiement. -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- Pour recevoir les détails d'exception des erreurs à des fins de débogage, définissez la valeur ci-dessous sur true. Définissez-la sur false avant le déploiement pour éviter la divulgation des informations d'exception. -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />-->
  </system.serviceModel>


  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings><add name="RssBddEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=JAGUAR-PC\SQLSERVER;Initial Catalog=RssBdd;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

这两个项目位于同一解决方案中。

我迷路了请帮助我!!!!

I'm actually trying to create a wpf project witch connected to the WCF via services references, I'm also using the MVVM pattern in my wpf project and I have a problem when I declare in my CTOR of my viewModel the serviceManager !

My view.xaml says me:
Could not find default endpoint element that references contract 'UserServiceReferences.IUserManagement' 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.

here is my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IUserManagement" 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>
        </bindings>
        <client>
            <endpoint address="http://localhost:2981/UserManagement.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserManagement"
                contract="UserServiceReference.IUserManagement" name="BasicHttpBinding_IUserManagement" />
        </client>
    </system.serviceModel>
</configuration>

and here my Web.config in my WCF service:

<?xml version="1.0"?>
<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
    </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- Pour éviter la divulgation des informations sur les métadonnées, définissez la valeur ci-dessous sur false et supprimez le point de terminaison des métadonnées ci-dessus avant le déploiement. -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- Pour recevoir les détails d'exception des erreurs à des fins de débogage, définissez la valeur ci-dessous sur true. Définissez-la sur false avant le déploiement pour éviter la divulgation des informations d'exception. -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />-->
  </system.serviceModel>


  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings><add name="RssBddEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=JAGUAR-PC\SQLSERVER;Initial Catalog=RssBdd;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Thoses two projects are in the same solution.

I'm lost please help me !!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘然心甜 2024-10-15 04:28:49

您使用的是 WCF 4.0,它使用简化的配置概念,并且如果在配置中未定义端点或通过代码添加没有端点,则将添加默认端点。

关于实际问题,我发现异常“UserServiceReferences.IUserManagement”中的合同名称与端点“UserServiceReference.IUserManagement”中定义的合同名称有所不同。请注意命名空间“UserServiceReference(s)”中的额外“s”。如果不是拼写错误,那么这可能是问题的原因。否则,请检查端点是否在正确的配置文件中定义。

HTH。

You're using WCF 4.0 which uses simplified configuration concepts and will add default endpoints, if no endpoints are defined in configuration or added through code.

about the actual issue, I see that there's difference in Contract name in exception 'UserServiceReferences.IUserManagement' and defined in Endpoint "UserServiceReference.IUserManagement". please note extra 's' in namespace 'UserServiceReference(s). if it's isn't typo, then that could be the cause of the issue. otherwise, check that endpoints are defined in correct configuration file.

HTH.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文