提供两个接口的 Web 服务导致 WPF 应用程序出现错误

发布于 2024-12-05 08:49:14 字数 4169 浏览 0 评论 0原文

我有一个提供两个接口的网络服务。一个是“MyAppNameData”,另一个是“MyAppNameSync”。我正在向 WPF 应用程序添加两个服务引用。在代码中,当我使用“MyAppNameData”引用时,我没有收到错误。当我使用“MyAppNameSync”时,会生成以下错误:

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.

我以完全相同的方式添加了两个引用,但是,MyAppNameData 是使用 BasicHttpBinding 添加的,MyAppNameSync 是使用 WSHttpBinding 添加的。我不知道为什么会这样。

以下是客户端 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>

任何建议都将不胜感激。

谢谢

I have a web service that provides two interfaces. One is "MyAppNameData" and the other is "MyAppNameSync". I am adding two service references to a WPF application. In the code, when I use "MyAppNameData" reference, I don't get an error. When I use "MyAppNameSync" the following error is generated:

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.

I added the two references in the exact same way but, MyAppNameData was added using BasicHttpBinding and MyAppNameSync was added with WSHttpBinding. I don't know why that is the case.

Here is the serviceModel element from the client's app.config file. As you can see, there is an endpoint element that references the contract 'MyAppNameSync.IMyAppNameSync', contrary to what the error message says:

    <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>

Any recommendations would really be appreciated.

Thanks

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

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

发布评论

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

评论(1

凉薄对峙 2024-12-12 08:49:14

好的。我现在可以使用了。我显然同时犯了几个错误。正如雷切尔在上面的评论中所建议的,我试图让一个最简单的案例发挥作用。但是,最初是无法做到的。从主机中删除其中一项服务,因此我只有 MyAppNameData.svc ,最初不起作用。我知道简单版本的 Web 服务过去可以工作,所以我尝试让一切恢复到该工作点。

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

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

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

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

OK. I have it working now. I apparently had several errors going at the same time. As Rachel suggested in her comment above, I tried to get a simplest case working. But, was initially unable to. Removing one of the services from the host, so I only had MyAppNameData.svc did not, initially, work. I knew the simple version of the web service worked in the past so, I tried to get everything back to that working point.

I used one of my existing ASP.NET web applications to point to the instance of the web service that I have been using for testing, and I was able to get that to work (even while having two services; MyAppNameData.svc and MyAppNameSync.svc in the host MyAppNameWebService). So, I knew that the problem was between my WPF application and the web service.

I had seen several discussion threads that stated "This error can arise if you are calling the service in a class library and calling the class library from another project". But, I thought I had accounted for that issue in my problem solving steps. But, when I stripped everything out of my WPF project, and rebuilt it all (for the 100th time), making sure "to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app" as stated in
this thread, I was able to get it to work!

I had attempted this solution before but, apparently I had still not resolved some other issue. I am no longer getting the error, and I am able to connect to, and use, the two separate services from the same host. So, I am in business.

Thank you all for your responses and suggestions. Now, on to other challenges!

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