我已使用 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/