c# - 使用soap客户端时出现InvalidOperationException

标签 c# .net wcf web-services soap

我已使用 vs2008 中的添加服务引用对话框添加为 wsdl 文件。

MyService serviceproxy = new MyService();

当我实例化服务代理时,我收到一个 InvalidOperationException ,其中包含以下文本(翻译自德语):

Could not find default endpoint element to the contract "ServiceName.ServiceInterface" in the service model refers client configuration section. This may be because: The application configuration file was not found or not an endpoint in the client element item is found, which corresponded to this contract.

其中servicename是我在vs2008中添加服务时给服务起的名称,ServiceInterface是为其自动生成的接口(interface)。

编辑 这是我的 app.config 中的内容:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="MyServiceBinding" 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>
    </system.serviceModel>

最佳答案

你的配置中需要这样的东西:

<client>
  <endpoint binding="basicHttpBinding" 
    bindingConfiguration="MyServiceBinding" contract="ServiceName.ServiceInterface"
    name="MyServiceEndpoint">
  </endpoint>
</client>

在你的标签内

我刚刚读了你的评论。

因此从端点配置中删除了地址。

您可以选择在代码中完全指定端点或仅指定地址,如下所示:

MyServiceClient proxy = new MyServiceClient();
proxy.Endpoint.Address = new EndpointAddress ("http://addressto your service"); //<-- address

关于c# - 使用soap客户端时出现InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2498871/

相关文章:

wcf - 在 WCF Web 编程模型中,如何编写具有一组查询字符串参数(即具有相同名称)的操作协定?

c# - 如何根据 C# 中的签名获取方法的唯一 ID?

c# - 如何从非常大的列表中按索引有效地删除元素?

C# sql server 2008 r2插入存储过程不起作用

.net - Mono 与 .NET Interop 的好奇心

javascript - 下拉更改加载时 knockout 火订阅

c# - 默认情况下将泛型类型参数设置为 object c#

c# - 如何为单个请求禁用 HttpWebRequest 中的 "Expect: 100 continue" header ?

c# - 在控制台应用程序中等待异步操作后,WCF 客户端挂起任何操作

wcf - SSL 错误 + WCF